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
Solved

open IE New window

Posted on 2001-08-05
6
650 Views
Last Modified: 2008-02-01
ShellExecute(handle, 'open', PChar(lblUrl.Caption), nil, nil, SW_SHOWNORMAL);

is the code I'me using, but this opens the page in a new IE window if there are none open and in an opened IE window if there was one open.
I want IE to ALWAYS open a NEW window and show this page.
how can I do this?
0
Comment
Question by:pin_plunder
6 Comments
 
LVL 1

Accepted Solution

by:
rootnash earned 25 total points
ID: 6354665
just in case u want a working (but longer) code, try this:

--------------

unit linktoweb;

interface

uses Windows, Dialogs, comobj;

procedure OpenIE(aURL: string);

implementation

function RegisterServiceProcess (dwProcessID, dwType: DWord) : DWord; stdcall; external 'KERNEL32.DLL';

procedure OpenIE(aURL: string);
var
  IE        : Variant;
  WinHanlde : HWnd;
begin
  if( VarIsEmpty(IE) )then
  begin
    IE := CreateOleObject('InternetExplorer.Application');
    IE.Visible := true;
    IE.Navigate(aURL);
  end
  else
  begin
    WinHanlde := FindWIndow('IEFrame', nil);
    if (0 <> WinHanlde) then
    begin
      IE.Navigate(aURL);
      SetForegroundWindow(WinHanlde);
    end
    else
      ShowMessage('Can''t open IE !');
  end;
end;
end.


and call for e.g.

  OpenIE('http://www.yoururl.com');


roots
0
 

Expert Comment

by:BryGuy
ID: 6356431
Heres a procedure I wrote to replace ShellExecute to always open in a new window:

procedure PseudoShellExecuteNewWindow (const Path : string);
var
  StartInfo     : TStartupInfo;
  ProcInfo      : TProcessInformation;
  ExePath       : array [0..MAX_PATH - 1] of char;
  FullExe       : string;
begin
  FillChar (StartInfo, SizeOf(StartInfo), 0);
  FillChar (ProcInfo, SizeOf(ProcInfo), 0);
  StartInfo.cb := SizeOf(StartInfo);

  //
  // Locate the associated executable - if none is found, default to
  // notepad
  //
  if FindExecutable (PChar(Path), nil, ExePath) > 32 then
    FullExe := string(ExePath) + ' "' + Path + '"'
  else
    FullExe := 'notepad ' + Path;

  CreateProcess (nil, PChar(FullExe), nil, nil, FALSE, DETACHED_PROCESS,
    nil, nil, StartInfo, ProcInfo);
end;


If you are tarteting IE only though, I would go ahead and use OLE.

I'd do something like:

procedure OpenInIeWin (const Url : string);
var
  Ie  : Variant;
  UrlVar,
  Flags,
  Frame,
  Post,
  Headers : OleVariant;
begin
  UrlVar := Url;
  Flags := $1;
  Frame := '_BLANK';
  try
    Ie := GetActiveOleObject ('InternetExplorer.Application');
  except
    try
      Ie := CreateOleObject ('InternetExplorer.Application');
    except
      Exit;
    end;
  end;
  Sleep (300); // possiblly fix the "server not available" error.
  Ie.Navigate2 (UrlVar, Flags, Frame, Post, Headers);
end;

Bryan Ashby
0
 
LVL 2

Expert Comment

by:Tasomia
ID: 6357132
uses
  ShellAPI, Registry;

procedure OpenURL(Url : string);
var
  ts :string;
begin
  with TRegistry.Create do try
    rootkey:= HKEY_CLASSES_ROOT;
    OpenKey('\htmlfile\shell\open\command',false);
    try
      ts:= ReadString('');
    except
      ts:= '';
    end;
    CloseKey;
  finally
    Free;
  end;
  if ts = '' then Exit;
  // remove quotes and commandline parameters
  ts:= Copy(ts,Pos('"',ts)+1,Length(ts));
  ts:= Copy(ts,1,Pos('"',ts)-1);
  ShellExecute(0,'open',pchar(ts),pchar(url),nil,sw_show);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  OpenURL('http://www.experts-exchange.com');
end;
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:pin_plunder
ID: 6358025
rootnash the points are already yours, but ...

is there any way to do the same for netscape?

thanks.

0
 
LVL 1

Expert Comment

by:rootnash
ID: 6358231
sorry, i tried tweaking it but it does not work in netscape. :(
0
 

Author Comment

by:pin_plunder
ID: 6359932
thanks a lot for your help
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

792 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