I need to open a browser window in Delphi 2005 Personal and then wait for the user to close it before returning to my application. It's a VCL for .NET project and I've tried an ActionList with a TBrowseURL but I can't find a way to wait for the window to close.
Any help would be appreciated.
Thanks
Ian
I think you'll need to mimic the behaviour to find out what program is
associated with html files. I don't think you can do this with ShellExecute
as it doesn't give you enough control. Maybe like this:
function RunProgram(ProgramName, Parameters, DocumentName: string; Wait:
Boolean): THandle;
var myProcess: Process;
ProgramNameBuilder: StringBuilder;
begin
ProgramNameBuilder := StringBuilder.Create(MAX_PATH);
FindExecutable(ExtractFileName(DocumentName),
ExtractFileDir(DocumentName), ProgramNameBuilder);
ProgramName := ProgramNameBuilder.ToString;
Parameters := '"' + DocumentName + '" ' + Parameters;
This will find the program associated with the HTML file. You are then ready
to launch the program, with the HTML file as a parameter. Launching the
program yourself means that you can wait for it to finish. Something like
this:
myProcess := Process.Create;
with myProcess do
begin
StartInfo.FileName := ProgramName;
StartInfo.Arguments := Parameters;
StartInfo.Verb := 'Open';
StartInfo.CreateNoWindow := False;
if Start() then
begin
WaitForInputIdle;
Result := GetForegroundWindow;
if IsIconic(Result) then ShowWindow(Result, SW_RESTORE);
if Wait then
begin
WaitForExit;
Application.BringToFront;
end;
end
else
Result := 0;
end;
Hope it helps
David
"Ian" <indi...@gmail.com> wrote in message
news:43be78bb$1...@newsgroups.borland.com...
The only problem I have with it is trying to find the FindExecutable procedure/function? I've looked for an hour for it and done plenty of 'Googling' but just can't get it!
If you could point me in the right direction, it would be much appreciated.
Regards
Ian
Yes - sorry, missed out the uses clause. You need to add 'ShellAPI' (for
FindExecutable), System.Text (for StringBuilder), and System.Diagnostics
(for the Process class).
Hope that does the trick.
David
Thankyou very much indeed for your helpful answers, I now have the whole process working well. One thing I haven't checked yet is whether this method waits for the particular window it opened to close or just any browser window to close if you see what I mean. One way to find out I suppose.....
Thanks again
Ian