== Demo code ==
type
TForm1 = class(TForm)
private
Identifier: Integer;
WndHandle: hWnd;
Watching: Boolean;
function WinExecAndGetHWnd(const fn: String): Boolean;
procedure WaitUntilGone;
end;
implementation
{$R *.DFM}
var
TPI: TProcessInformation;
function EnumFunc(H: hWnd; TF: Tsplash_screen): Boolean; StdCall;
var
TheID : LongInt;
begin
With TF do begin
GetWindowThreadProcessId(H, @TheID);
if TheID = Identifier then begin
WndHandle := H;
Result := False;
end
else
Result := True;
end;
end;
function TSplash_screen.WinExecAndGetHWnd(const fn: String): Boolean;
var
TSI: TStartupInfo;
begin
WndHandle := 0;
FillChar(TSI, SizeOf(TSI), 0);
TSI.cb := SizeOf(TSI);
if CreateProcess(nil, PChar(fn), nil, nil, False,
NORMAL_PRIORITY_CLASS,
//CREATE_NEW_PROCESS_GROUP or
//DETACHED_PROCESS or
nil, nil, TSI, TPI) then begin
Identifier := TPI.dwProcessId;
CloseHandle(TPI.hThread);
WaitForInputIdle(TPI.hProcess, 10000);
EnumWindows(@EnumFunc, LongInt(Self));
if (WndHandle = 0) and (GetPlatform = tpWinNT) then
showmessage('Windows NT cannot open the requested application.');
end;
Result := WndHandle <> 0;
end;
procedure TSplash_screen.WaitUntilGone;
var
ECP: Integer;
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(TPI.hProcess, ECP);
until (ECP <> STILL_ACTIVE) or Application.Terminated;
CloseHandle(TPI.hProcess);
end;
procedure RunApp;
begin
if Watching then
Exit;
if WinExecAndGetHWnd('AppName.exe') then
begin
Watching := True;
WaitUntilGone;
Watching := False;
end;
end
== End Code ==
Sorry about the lack of comments, but it should but at least a little
obvious what's going on.
========================================================
Luke Pascoe Delphi Programmer
enSynergy Consulting LTD
[EMAIL PROTECTED] +64-9-3551593 fax +64-9-3551590
Level 4, 10-12 Federal St, Auckland, New Zealand
PO Box 32521, Devonport, Auckland 1330, New Zealand
================== I.H.T.F.P. ==========================
> -----Original Message-----
> From: Graham Mayes [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, 17 May 2001 4:11 p.m.
> To: Multiple recipients of list delphi
> Subject: [DUG]: WinExec
>
>
> I have a programme which runs others using WinExec
> (CreateProcess seems a
> little complicated for my small understanding).
>
> Upon returning from the called programme (eg Word), I want my
> programme to
> perform an action immediately and automatically, but . . it
> appears the
> window of my programme is not active until clicked and
> therefore I cannot
> think of an event (like 'On Activate') upon which to 'hang'
> the code for the
> action I want performed. Is there a solution?
>
> Again 'yes' will not be overly helpful. :)
>
> Regards
> Graham.
>
> --------------------------------------------------------------
> -------------
> New Zealand Delphi Users group - Delphi List -
> [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
>
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"