> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Dennis Chuah
> Sent: Wednesday, 19 January 2000 09:01
> To: Multiple recipients of list delphi
> Subject: RE: [DUG]: FWD: Closing Other Applications
>
>
>
> When you start those other applications (say, using
> ShellExecuteEx), you can
> obtain the process handle.  By testing for the signalled state of the
> process handle, you can tell if the other app has closed down.  A
> process is
> complete when its state is signalled.  Use either WaitForMultipleObjects /
> WaitForSingleObject WinAPI call.

This is what my code looks like:

function CloseApplication(WClass,WTitle:string; Delay:Longint):integer;
var Hnd:HWND;
    WRes:DWord;
    hProc:PDWord;
begin
     New(hProc);
     Result:=-1;
     hProc^:=1;
     Hnd:=FindWindow(PChar(WClass),PChar(WTitle));
     if Hnd<>0 then //The window exists
     begin
          if IsWindowEnabled(Hnd) then  //The window is enabled (no modal
dialogs)
          begin
               GetWindowThreadProcessID(Hnd,hProc);
               PostMessage(Hnd,WM_CLOSE,0,0); //Tell it to close
               WRes:=WaitForSingleObject(hProc^,Delay); //Wait to see if it
closed
[...]

The problem is detecting if the application actually closed or not.

If the application closed successfully I am getting (typical values)
Hnd = 940
hProc^ = -532075
WRes = WAIT_FAILED
GetLastError = INVALID_HANDLE

If the application did _not_ close successfully I am getting (typical
values)
Hnd = 242
hProc^ = -530451
WRes = WAIT_FAILED
GetLastError = INVALID_HANDLE

so WaitForSingleObject always fails, regardless.

According to MS the WaitForSingleObject call should return WAIT_TIMEOUT if
it did not close.

============================================
Patrick Dunford, Christchurch, NZ
EnzedRailWeb Sites
http://patrick.dunford.com/enzedrailweb/

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to