Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opening a browser window in D2005 Personal

0 views
Skip to first unread message

Ian

unread,
Jan 6, 2006, 8:03:39 AM1/6/06
to

Hi all

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

David Wilcockson

unread,
Jan 8, 2006, 6:29:00 AM1/8/06
to
The TBrowseUrl simply sends a ShellExecute to the operating system.

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...

Ian

unread,
Jan 8, 2006, 12:23:26 PM1/8/06
to

Thankyou very much for that David, it looks like exactly what I need.

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

David Wilcockson

unread,
Jan 8, 2006, 1:38:27 PM1/8/06
to
> 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.
>

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

Ian

unread,
Jan 9, 2006, 5:26:08 AM1/9/06
to

That's it! I was trying to import it from a DLL, and trust me it was going badly. I was trying Shell32.

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

0 new messages