Solved

How do open up a browser...

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

739 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