Examples Delphi

OPEN INTERNET BROWSER FROM DELPHI...
>I´m executing an application from within another one. I am using winexec.
>How can I close the application afterwards, when I don´t need it anymore????
Send the window a message telling it to close itself. Look up SendMessage
and WM_QUIT.
> I want to open an url on a new browser window, but using
> shellexecute(handle,'open',pchar('http://etc.'),nil,nil,sw_shownormal);
> it always open it on the same window. Any tip?
Notice that when you use this approach you are allowing windows to handle
the details for you. All you are providing is the resource/document/file
on which to operate and you are relying on the fact that windows can do
something with it. Try doing this sort of thing with a file such as a
.AnyBogusExtension and see what windows will do. With this method, I don't
know if you can specify a new process for your request, I'd love to know
myself.
But, the other approach is to handle the details yourself. Instead of
giving windows a url and letting it take care of the rest, start the
application you want, usually the app will allow you pass it cmd line
parameters for a document to open or a specific action.
Just wanted to point out the distinction between the two approaches.
From: "Steve Helgeson"
To:
Subject: RE: Open URL on a new window
Date sent: Tue, 16 Mar 1999 15:04:40 -0500
Send reply to: Delphi@Kyler.com
Mauricio,
You want to launch your browser as a new application that takes the URL as
an argument.
To do this, you need to know the name of your browser application (and the
URL to open).
It looks like your browser is what's associated with opening html files.
That being the case, the program that opens html files is located in your
registry at:
HKEY_CLASSES_ROOT\'http\shell\open\command
You'll need to strip off the quote marks and stuff. Here's a function that
works for me with either Netscape or Internet Explorer (Mosaic does not
install itself in the registry here just by installing Mosaic; if you're
using Mosaic as your browser, Mosaic has to be explicitly associated with
opening html files. I don't know if this works with Opera):
function TMyForm.GetBrowser: String;
var
Browser: String;
I: Integer;
Reg: TRegistry;
begin
Reg := TRegistry.Create;
with Reg do
try
RootKey := HKEY_CLASSES_ROOT;
if not OpenKey('http\shell\open\command',False) then Browser := ''
else Browser := ReadString('');
CloseKey;
finally
Free;
Reg := nil;
end;
{this strips off any parameters after the browser.exe }
I := Pos('.exe',LowerCase(Browser));
if I > 0 then Browser := Copy(Browser, 1, (I+3));
{this strips out any quote marks }
I := Pos('"',Browser);
while I > 0 do
begin
Delete(Browser,1,I);
I := Pos('"',Browser);
end;
Result := Browser;
end;
Then once you have the location\name of the browser and your URL, open it in
a new browser window with:
ShellExecute(GetDesktopWindow(), nil, PChar(Browser), PChar(URL), nil,
SW_SHOWNORMAL);
You can also do error handling on this with:
Result := ShellExecute(GetDesktopWindow(), nil, PChar(Browser), PChar(URL),
nil, SW_SHOWNORMAL);
if Result < 32 then
begin
if Result = 0 then ShowMessage('Out of Memory or Resources')
else if Result = ERROR_FILE_NOT_FOUND then ShowMessage('File Not Found')
else if Result = ERROR_PATH_NOT_FOUND then ShowMessage('Path Not Found')
else if Result = ERROR_BAD_FORMAT then ShowMessage('Bad Format')
else ShowMessage('Error [' + IntToStr(Result) + ']');
end;
{those are the explicit ones I care about}
HTH,
Steve Helgeson
Lamplighter Software