The reason you're getting INVALID_HANDLE is because... wait for it... it's
an invalid handle. :)  GetWindowThreadProcessID returns a handle to the
Process _ID_, NOT a handle to the process.

Stick in an extra line:

        GetWindowThreadProcessID(Hnd,hProc);
        ProcHandle := OpenProcess(SYNCHRONIZE, False, hProc^);
        PostMessage(Hnd,WM_CLOSE,0,0); //Tell it to close
        WRes:=WaitForSingleObject(ProcHandle,Delay); //Wait to see if it
closed

Cheers,
Carl

-----Original Message-----
From: Patrick Dunford [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 19 January 2000 14:58
To: Multiple recipients of list delphi
Subject: RE: [DUG]: FWD: Closing Other Applications


               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

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

Reply via email to