Hi All.
I have a bit of code that does an execute and waits for the app. to 
close.
What I want to do is execute a game and know when its finished, BUT when 
I use my code, it starts to execute the app, but then it stops and 
returns an error code of zero which means its finished...BUT it never 
started.
This is teh code I use. anyone got anything better?

Jeremy


function TfrmMain.WinExecAndWait32(Path: PChar; Visibility: Word): 
integer;
var Msg: TMsg;
    lpExitCode: cardinal;
    StartupInfo: TStartupInfo;
    ProcessInfo: TProcessInformation;
begin
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  with StartupInfo do
  begin
    cb := SizeOf(TStartupInfo);
    dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
    wShowWindow := visibility; {you could pass sw_show or sw_hide as 
parameter}
  end;

  if CreateProcess(nil, path, nil, nil, False, NORMAL_PRIORITY_CLASS, 
nil, nil, StartupInfo,
                   ProcessInfo) then
  begin
    repeat
      while PeekMessage(Msg, 0, 0, 0, pm_Remove) do
      begin
        if Msg.Message = wm_Quit then Halt(Msg.WParam);
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
      GetExitCodeProcess(ProcessInfo.hProcess,lpExitCode);
    until lpExitCode <> Still_Active;

    with ProcessInfo do {not sure this is necessary but seen in in some 
code elsewhere}
    begin
      CloseHandle(hThread);
      CloseHandle(hProcess);
    end;
    Result := 0; {success}
  end else Result := GetLastError;
end;

---------------------------------------------------------------------------
    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"
Web Archive at: http://www.mail-archive.com/delphi%40delphi.org.nz/

Reply via email to