Solved

How do open up a browser...

Posted on 1998-08-28
5
143 Views
Last Modified: 2010-04-04
I am writing a Delphi app and would like to know how to include a link to my web site and also to my e-mail.
I would like to know how to make it so that the user just clicks and the default browser opens up and goes to my site.
I know I have to use ShellExecute but how would I go about this?
0
Comment
Question by:pf2
5 Comments
 
LVL 4

Expert Comment

by:erajoj
ID: 1337982
Hi,

Simplest way:
uses ...ShellAPI; // don't forget

  ShellExecute( 0, 'open', 'http://www.mydomain.com/~MyName/StartPage.html', nil, nil, SW_SHOW );

/// John
0
 
LVL 1

Expert Comment

by:Greedy
ID: 1337983
You can also do this

function MyCreateProcess(sExecutableFilePath : string): string;
var
  pi: TProcessInformation;
  si: TStartupInfo;
begin
  FillMemory(@si, sizeof( si), 0 );
  si.cb := sizeof( si );
  CreateProcess(Nil, PChar(sExecutableFilePath), Nil, Nil, False,
                NORMAL_PRIORITY_CLASS, Nil, Nil, ci, pi);
  //wait until done
  CloseHandle (pi.hProcess);
  CloseHandle(pi.hThread);
end;



0
 
LVL 4

Accepted Solution

by:
itamar earned 50 total points
ID: 1337984
The answer recomended by Inprise Techinal Information:

>>>

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
      DdeMan,
     {$IFDEF WIN32}
       Registry; {We will get it from the registry}
     {$ELSE}
       IniFiles; {We will get it from the win.ini file}
     {$ENDIF}

     {$IFNDEF WIN32}
       const MAX_PATH = 144;
     {$ENDIF}

     function GetProgramAssociation (Ext : string) : string;
     var
     {$IFDEF WIN32}
       reg: TRegistry;
       s : string;
     {$ELSE}
       WinIni : TIniFile;
       WinIniFileName : array[0..MAX_PATH] of char;
       s : string;
     {$ENDIF}
     begin
     {$IFDEF WIN32}
       s := '';
       reg := TRegistry.Create;
       reg.RootKey := HKEY_CLASSES_ROOT;
       if reg.OpenKey('.' + ext + '\shell\open\command',
                      false) <> false then begin
       {The open command has been found}
         s := reg.ReadString('');
         reg.CloseKey;
       end else begin
       {perhaps thier is a system file pointer}
         if reg.OpenKey('.' + ext,
                        false) <> false then begin
           s := reg.ReadString('');
           reg.CloseKey;
           if s <> '' then begin
          {A system file pointer was found}
             if reg.OpenKey(s + '\shell\open\command',
                            false) <> false then
          {The open command has been found}
               s := reg.ReadString('');
             reg.CloseKey;
           end;
         end;
       end;
      {Delete any command line, quotes and spaces}
       if Pos('%', s) > 0 then
         Delete(s, Pos('%', s), length(s));
       if ((length(s) > 0) and
           (s[1] = '"')) then
         Delete(s, 1, 1);
       if ((length(s) > 0) and
           (pos('"', s) > 0)) then
         Delete(s, pos('"', s), Length(s));
       while ((length(s) > 0) and
              (s[length(s)] = #32)) do
         Delete(s, Length(s), 1);
     {$ELSE}
       GetWindowsDirectory(WinIniFileName, sizeof(WinIniFileName));
       StrCat(WinIniFileName, '\win.ini');
       WinIni := TIniFile.Create(WinIniFileName);
       s := WinIni.ReadString('Extensions',
                               ext,
                               '');
       WinIni.Free;
      {Delete any command line}
       if Pos(' ^', s) > 0 then
         Delete(s, Pos(' ^', s), length(s));
      {$ENDIF}
       result := s;
     end;

     procedure StartNewBrowserWindow(URL : string);
     var
       DDEConv : TDDEClientConv;
       URLFired : bool;
       App : string;
       UpApp : string;
       p : array[0..MAX_PATH] of char;
     begin
       UrlFired := false;
       App := GetProgramAssociation('HTM');
       UpApp := Uppercase(App);
       Delete(App, Pos('.EXE', UpAPP), length(App));
       if Pos('NETSCAPE.EXE',
              UpApp) > 0 then begin
         DDEConv:=TDDEClientConv.Create(nil);
         DDEConv.ServiceApplication := App;
         if DDEConv.SetLink('NETSCAPE' , 'WWW_OpenURL') then
           if DDEConv.RequestData(URL +
                                  ',,0x0,0x0') <> nil then
             if DDEConv.SetLink('NETSCAPE', 'WWW_Activate') then
               URLFired := DDEConv.RequestData('0xFFFFFFFF,0x0') <> nil;
         DDEConv.Free;
       end else
       if Pos('IEXPLORE.EXE',
              UpApp) > 0 then begin
         DDEConv:=TDDEClientConv.Create(nil);
         DDEConv.ServiceApplication := App;
         if DDEConv.SetLink('iexplore', 'WWW_OpenURL') then
           if DDEConv.RequestData(URL + ',,0') <> nil then
             if DDEConv.SetLink('iexplore', 'WWW_Activate') then
               URLFired := DDEConv.RequestData('0,0') <> nil;
         DDEConv.Free;
       end;
       if UrlFired = false then
         WinExec(StrPCopy(@p, URL), SW_SHOWNORMAL);
     end;

     procedure TForm1.Button1Click(Sender: TObject);
     begin
       Label1.Caption := GetProgramAssociation('HTM');
       StartNewBrowserWindow('http://www.borland.com');
     end;

end.

If you have problems with cutting & pasting, place a comment with yoy e-mail so I can send you the source.

IHTH
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1337985
Here is how to use it.....

ShellExecute(0, 'open', 'http:\www.yahoo.com',nil,nil, SW_NORMAL);//for website...
ShellExecute(0, 'open', 'mailto:viktor@megsinet.net',nil,nil, SW_NORMAL);//for e-mail

Hope this helps =)

Regards,
Viktor Ivanov
0
 

Expert Comment

by:manolis_afentakis
ID: 1337986

uses fmxutils

(see online Help)

.
   executeFile('www.inprise.com','','',1);

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

896 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

18 Experts available now in Live!

Get 1:1 Help Now