Solved

open IE New window

Posted on 2001-08-05
6
643 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
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.

 

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

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

930 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

12 Experts available now in Live!

Get 1:1 Help Now