?
Solved

Starting Email & Browser From My App

Posted on 2001-08-21
5
Medium Priority
?
160 Views
Last Modified: 2010-04-06
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.
0
Comment
Question by:tecbuilder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Accepted Solution

by:
YodaMage earned 1200 total points
ID: 6410929
var
  StartInfo : _STARTUPINFOA;
  ProcessInfo : _PROCESS_INFORMATION;
begin
  GetStartupInfo(startinfo);
  CreateProcess('*.exe', PChar('*.exe'), nil,
  nil, false, CREATE_NEW_CONSOLE,
  nil, nil, StartInfo, ProcessInfo);
end;

Just replace my *.exe with the file you need to open. This will not open the default though, and create process cannot open a default as far as I know. You'll have to write the code to determine the appropriate exe.

I use shellexecute and have had no problem on w2k.
Code as  taken from my app:

var
  temp : string[50];
begin
  temp := qryfirm.fieldbyname
   ('client_procede_path').asstring;
  ShellExecute(Handle, 'OPEN', PChar(temp + '\' +
   edproc.text), nil, nil, SW_MAXIMIZE);
end;

*edproc.text is the name of an html file.
0
 
LVL 2

Expert Comment

by:RickHalle
ID: 6411031
I agree. ShellExecute has not given me any problems either. CreateProcess will work but you need to know the exe to execute in advance.

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
0
 

Expert Comment

by:eshipman
ID: 6411595
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(Sender: TObject);
begin
 BrowseTo('http://www.experts-exchange.com', '',
          '');
end;

procedure TForm1.btnEmailToClick(Sender: TObject);
begin
 BrowseTo('mailto:bill_gates@microsoft.com', '',
          '');
end;

0
 
LVL 4

Expert Comment

by:YodaMage
ID: 6418219
What else do you need?
0
 
LVL 6

Author Comment

by:tecbuilder
ID: 6418468
28 hour days.  :)  Sorry for the delay.  Thanks for your help.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month15 days, 2 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question