Solved

How do open up a browser...

Posted on 1998-08-28
5
142 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 Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

14 Experts available now in Live!

Get 1:1 Help Now