Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Waiting until browser is closed ???

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
Hi all,

Thanks for reading my post, what i want to do is this:
I have a webbrowser (whichever is default) run a file that
is created in my editor and i want the "test run"-button to
be disabled until the browser is closed. But I cannot get that to work.

Now I remember once reading something like this being done
through CreateProcess and WaitForProcess but I cant find
that post anywhere :-( And also I cannot get it to work,
the helpfile being a tad bit vague on this.

So if you guys have any helpful tips or maybe even a bit of
code for me to work from, I'd be most grateful!


[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
This is Footpad's post to me earlier.
I have modified it slightly

procedure TForm1.Button1Click(Sender: TObject);
begin
execwait('Iexplore.exe','C:\Program Files\Internet Explorer\','c:\test.htm');
end;


function Tform1.execWait( strFile, strPath, strOpts : String ) :
Boolean;
{ ---------------------------------------------------------------
Executes an external program and waits for it to exit. The
parameters are:

-- strFile: The name of the program to execute
-- strPath: The directory to use.
-- strOpts: Any command line options needed.

Return value indicates if the application executed and
completed
successfully (TRUE). If not, FALSE is returned. (Note full
error handling deleted for this posting.)

Please note that this implementation is based on Pat Richey's
WinExecAndWait32, as posted to several newsgroups over the past
few years; for more info, search groups.google.com
---------------------------------------------------------------
}
var
si : tStartupInfo; { Startup info for spawned process }
pi : tProcessInformation; { Process handle for spawned process
}
dwRetval : dWORD; { Return value from createProcess }
begin

{ Initialize the startup info record }
fillChar( si, sizeOf( si ), #0 );
with si do
begin
cb := Sizeof( StartupInfo );
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := sw_ShowNormal;
end; { with }

{ try to launch the application }
if not createProcess( nil, pchar( strPath + strFile + ' ' +
strOpts ), nil,
nil, FALSE, CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil, pchar( strPath ), si, pi ) then
begin
dwRetval := getLastError; { save system error info }
// error handling deleted for brevity; see online help.
result := FALSE; { trigger offer to cancel remaining
items }
end
else
begin
repeat
// application.processMessages; { wait }
until ( WaitforSingleObject( pi.hProcess, 500 ) <>
WAIT_TIMEOUT );
{ the following saved for future use }
GetExitCodeProcess( pi.hProcess, dwRetval );
CloseHandle( pi.hProcess ); { clean up }
CloseHandle( pi.hThread );
result := TRUE;
end;
end;
 
Code:
 repeat
 until ( WaitforSingleObject( pi.hProcess, 500 ) <>
       WAIT_TIMEOUT );
?????
Process' state is set to singnaled when it's exits, so that means that your WaitForSingleObject will wait a half of a second for a process and then will exit the Wait loop. I suggest using WAIT_OBJECT_0 and set the wait time to INFINITE.
Code:
 repeat
 until (WaitforSingleObject(pi.hProcess, INFINITE) <>
  WAIT_OBJECT_0);
Best regards.

--- markus
 
Thanks allot guys!

I'll get on this this evening, I have a lil brother to entertain right now lol :-D

[bobafett] BobbaFet [bobafett]

Everyone has a right to my opinion.
E-mail me at caswegkamp@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top