{
Example: AttachPlot('DEMO.GUI',2000).
Prepare attachment string like: @attachment demo_gui.gif
to send image of DEMO.GUI window by email via &EmlSrv as
attacment. Also create in MailBox directory (of &EmlSrv)
BMP and GIF files with window plot to be attached.
Returt empty string in case of any error.
}
function AttachPlot(Win:String; TimeOut:Integer):String;
var i,pid:Integer; cmd,bmp,gif,nconvert:String; ms:Real;
begin
 cmd:=''; bmp:=''; gif:='';
 nconvert:=ParamStr('FileSearch nconvert.exe');
 for i:=1 to Length(Win) do if Pos(Win[i],'    ')=0 then
 if Pos(Win[i],'&.;:\/&*+,|')>0 then bmp:=bmp+'_' else bmp:=bmp+Win[i];
 bmp:=AddBackSlash(AddBackSlash(ParamStr('DaqDataPath'))+'MailBox')+LoCaseStr(bmp);
 bmp:=ForceExtension(bmp,'.bmp');
 gif:=ForceExtension(bmp,'.gif');
 if FileErase(bmp) then
 if FileErase(gif) then
 if FileExists(nconvert) then
 if RefFind('Window '+Win)<>0 then
 if WinDraw(Win+'|SaveBmp=4bit,'+bmp) then begin
  ms:=msecnow;
  while (msecnow-ms<TimeOut) and not FileExists(bmp) do b:=Sleep(1) and (wdt_Reset(True)>0);
  if FileExists(bmp) then begin
   pid:=Task_Init(nconvert+' -out gif '+ExtractFileName(bmp)+ExtractFileExt(bmp));
   i:=Length(Task_Ctrl(pid,'Display=0'))+
      Length(Task_Ctrl(pid,'HomeDir='+ExtractFilePath(bmp)));
   if Task_Run(pid) then begin
    ms:=msecnow;
    while (msecnow-ms<TimeOut) and Task_Wait(pid,0) do b:=Sleep(1) and (wdt_Reset(True)>0);
    if FileExists(gif) then cmd:='@attachment '+ExtractFileName(gif)+ExtractFileExt(gif)+CRLF;
   end;
   b:=Task_Free(pid);
  end;
 end;
 AttachPlot:=cmd; nconvert:=''; cmd:=''; bmp:=''; gif:='';
end;
