Solved

How do open up a browser...

Posted on 1998-08-28
5
145 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
build html 5 client that connect to indy Tidtcpserver 3 396
Internet Explorer View Settings Question 15 111
code issue 8 130
creating threads in delphi 1 104
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 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