Good morning to all,
there's a way, at program exit, to show a message that remain visible even when the program itself is closed?
What i need is check for a specif usb drive, if found could be a nice feature show a message that informs the user that have to remove the usb.
I don't know if is possibile with the tms message library.
Now what i do is create a text file, open a notepad and load the text file ..... but (even works) is not what i'm looking for.
I also tried with msg.exe ... but, when the program close, the message windows will be close at the same time.
You can use this code as basis (msg.exe is supposed to be in c:\windows\system32 - or wherever your windows directory is, adapt as needed - but for some reason on my PC it was somewhere else, so I search for it)
FUNCTION FindFile(CONST StartDir,FileName : STRING) : TFileName;
VAR
SR : TSearchRec;
BEGIN
Result:=TPath.Combine(StartDir,FileName);
IF FileExists(Result) THEN EXIT;
IF FindFirst(TPath.Combine(StartDir,'*'),$3F,SR)=0 THEN
REPEAT
IF (SR.Attr AND $10=$10) AND (SR.Name[1]<>'.') THEN BEGIN
Result:=FindFile(TPath.Combine(StartDir,SR.Name),FileName);
IF Result<>'' THEN EXIT
END
UNTIL FindNext(SR)<>0;
Result:=''
END;
procedure TForm1.Button1Click(Sender: TObject);
begin
VAR Prog := 'c:\windows\system32\msg.exe';
IF NOT FileExists(Prog) THEN Prog:=FindFile('C:\Windows\WinSxS','msg.exe');
VAR Tail := '* This is a test...';
VAR SI : STARTUPINFO;
FillChar(SI,SizeOf(SI),0);
SI.cb:=SizeOf(SI); SI.wShowWindow:=SW_SHOW;
VAR PI : PROCESS_INFORMATION;
FillChar(PI,SizeOf(PI),0);
var CmdLine := '"'+Prog+'" '+Tail;
UniqueString(CmdLine);
if not CreateProcess(NIL,PChar(CmdLine),NIL,NIL,FALSE,0,NIL,NIL,SI,PI) then RaiseLastOSError;
Application.Terminate
end;