Board index » delphi » Ending an app launched within Delphi prog

Ending an app launched within Delphi prog

I'm trying to figure out how to recognise when the user has exited the
program launched during my application. I use the CreateProcess or WinExec
to launch this program, and I want to know when the user has
closed/terminated it. Please help.

Thanks. Jason.

 

Re:Ending an app launched within Delphi prog


One thing you could do is finding out if the handle you get from your
excute function is still valid. If you do this regularly you know the
program has ended when is stops being valid.

succes Arjan

J <ja...@carval.co.uk> wrote in article
<01bc9ea3$03f866c0$7ba29...@carval.zynet.co.uk>...

Quote
> I'm trying to figure out how to recognise when the user has exited the
> program launched during my application. I use the CreateProcess or

WinExec

Re:Ending an app launched within Delphi prog


In article <01bc9ea3$03f866c0$7ba29...@carval.zynet.co.uk>, J
<ja...@carval.co.uk> writes

Quote
>I'm trying to figure out how to recognise when the user has exited the
>program launched during my application. I use the CreateProcess or WinExec
>to launch this program, and I want to know when the user has
>closed/terminated it. Please help.

In Delphi 1, you kick off the 'spawned' process with something like:

  MyProg_Handle :=
     WinExec(MyProg_Name, SW_SHOWMINNOACTIVE);

when you want to kill it, you can then do:

function EnumProc(WinHandle: HWnd; hTaskHandle: LongInt): Boolean; far;
begin
  if (hTaskHandle = GetWindowWord(WinHandle, GWW_HINSTANCE)) then begin
    SendMessage(WinHandle, WM_CLOSE, 0, 0);
    Result := True;
  end
  else begin
    Result := False;
  end;
end;

{ --- Loop through all the windows until you find MyProg
      and then shut it down --- }

  EnumWindows(@EnumProc, MyProg_Handle);

Easy, innit?  John

+-------------------+--------------------------------------------------+
John P.McCreesh     | Net:   john.mccre...@forbolancs.co.uk
Forbo-Lancaster Ltd.| X.400: c=GB,a=CWMAIL,p=FORBO,s=McCreesh
Lancaster, England  | Voice: +44 (0)1524 65222 Fax: +44 (0)1524 61638

Other Threads