Solved

Starting Email & Browser From My App

Posted on 2001-08-21
5
154 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
5 Comments
 
LVL 4

Accepted Solution

by:
YodaMage earned 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now