Solved

open IE New window

Posted on 2001-08-05
6
656 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
[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
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
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!

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

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