tecbuilder
asked on
Starting Email & Browser From My App
What is the code that I need to use that would open a user's default email or web browser program depending upon which button they clicked on. I know I need to use the onClick event. This code must also be compatible with W2K, NT, ME, and 9x. I have heard there are issues with ShellExecute and W2K and have been told to use CreateProcess instead. Also, does my app. need to care about what happens to the email and web browser program. As far as I am concerned, I don't care when the user returns to my program. They can go back and forth between the two.
Therefore, the solution I am looking for is the code to open email and web browser using the CreateProcess API from an onClick event.
Therefore, the solution I am looking for is the code to open email and web browser using the CreateProcess API from an onClick event.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
uses ...,ShellApi;
procedure TForm1.BrowseTo(sURL, sBrowser, sDir :String);
var
sei: TShellExecuteInfo;
begin
ZeroMemory(@sei, sizeof(sei));
with sei do
begin
cbSize := SizeOf(sei);
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Form1.Handle;
lpVerb := 'open';
// Need to see if sBrowser empty, if so, pass url to lpFile parameter
if sBrowser <> #0 then
lpFile := PChar(sBrowser)
else
lpFile := PChar(sURL);
lpParameters := PChar(sURL);
lpDirectory := PChar(sDir);
nShow := SW_SHOWNORMAL;
end;
ShellExecuteEX(@sei);
end;
procedure TForm1.btnBrowseToClick(Se nder: TObject);
begin
BrowseTo('http://www.experts-exchange.com', '',
'');
end;
procedure TForm1.btnEmailToClick(Sen der: TObject);
begin
BrowseTo('mailto:bill_gate s@microsof t.com', '',
'');
end;
procedure TForm1.BrowseTo(sURL, sBrowser, sDir :String);
var
sei: TShellExecuteInfo;
begin
ZeroMemory(@sei, sizeof(sei));
with sei do
begin
cbSize := SizeOf(sei);
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Form1.Handle;
lpVerb := 'open';
// Need to see if sBrowser empty, if so, pass url to lpFile parameter
if sBrowser <> #0 then
lpFile := PChar(sBrowser)
else
lpFile := PChar(sURL);
lpParameters := PChar(sURL);
lpDirectory := PChar(sDir);
nShow := SW_SHOWNORMAL;
end;
ShellExecuteEX(@sei);
end;
procedure TForm1.btnBrowseToClick(Se
begin
BrowseTo('http://www.experts-exchange.com', '',
'');
end;
procedure TForm1.btnEmailToClick(Sen
begin
BrowseTo('mailto:bill_gate
'');
end;
What else do you need?
ASKER
28 hour days. :) Sorry for the delay. Thanks for your help.
Here is what I am using for URL's and Email:
procedure ShellOutRun(sUrl: String);
begin
sUrl := Trim(sUrl);
ShellExecute(0, Nil, PChar(sUrl), Nil, Nil, SW_NORMAL);
end;
Rick Halle