Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 673
  • Last Modified:

open IE New window

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
pin_plunder
Asked:
pin_plunder
1 Solution
 
rootnashCommented:
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
 
BryGuyCommented:
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
 
TasomiaCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
pin_plunderAuthor Commented:
rootnash the points are already yours, but ...

is there any way to do the same for netscape?

thanks.

0
 
rootnashCommented:
sorry, i tried tweaking it but it does not work in netscape. :(
0
 
pin_plunderAuthor Commented:
thanks a lot for your help
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now