New Tip - ...open local files in a TWebbrowser and start links directly ?

  • From: "SwissDelphiCenter.ch" <newsletter@xxxxxxxxxxxxxxxxxxxx>
  • To: sdcnewtip@xxxxxxxxxxxxx
  • Date: Tue, 5 Mar 2002 18:09:34 +0100

* SwissDelphiCenter new Tip newsletter
* www.swissdelphicenter.ch
*
* To unsubscribe send a mail to sdcnewtip-request@xxxxxxxxxxxxx with the
* subject unsubscribe


Hallo,

Folgender neuer Tip ist neu auf SwissDelphiCenter verfügbar:

Besuchen Sie die Programmier Tips unter 
http://www.swissdelphicenter.ch/de/tipsindex.php


Bewerten Sie diesen Tip nach Schwierigkeitsgrad, Nützlichkeit und Gesamthaft auf
http://www.swissdelphicenter.ch/de/showcode.php?id=1057



Autor:
Thomas Stutz <tom@xxxxxxxxxxxxxxxxxxxx>
http://www.swissdelphicenter.ch


-------------
...lokale Dateien in einen TWebbrowser laden und Links direkt starten ?
-------------
Kategorie: Objekte/ActiveX



{
  This example shows how to open local files in a TWebbrowser 
  and start links directly without showing a Dialog.
}

{
  Dieses Beispiel zeigt, wie man lokale Dateien in einem TWebbrowser 
  öffnen kann und wie man lokale Links direct ausführen kann ohne
  dass ein Dialog erscheint.
}


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure WebBrowser1BeforeNavigate2(Sender: TObject;
      const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
      Headers: OleVariant; var Cancel: WordBool);
  private
    FIsStartPage: Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  ShellApi;


// Open a local page:
procedure TForm1.Button1Click(Sender: TObject);
const
 LOCAL_PAGE ='C:/StartPage.htm'
begin
  FIsStartPage := True;
  Webbrowser1.Navigate('file:///' + LOCAL_PAGE);
  FIsStartPage := False;
end;


procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
var
  newURL: string;
begin
  newURL := URL;
  // For local links, don't show a dialog but open the file directly
  if (not FIsStartPage) and FileExists(newURL) then
  begin
    Cancel := True;
    ShellExecute(Application.Handle, 'open', PChar(newURL), nil, nil, 
SW_NORMAL);
  end;
end;





Best Regards
SwissDelphiCenter Team
www.swissdelphicenter.ch
[automatisch generierte EMail]


----------------------------------------------------
ENGLISH NEWSLETTER
----------------------------------------------------

Hi,

This new tip is new available on SwissDelphiCenter.ch:

Visit the programming tips at http://www.swissdelphicenter.ch/en/tipsindex.php


Rate this tip after skill, useful and overall at
http://www.swissdelphicenter.ch/en/showcode.php?id=1057



Author:
Thomas Stutz <tom@xxxxxxxxxxxxxxxxxxxx>
http://www.swissdelphicenter.ch


-------------
...open local files in a TWebbrowser and start links directly ?
-------------
Category: Objects/ActiveX



{
  This example shows how to open local files in a TWebbrowser 
  and start links directly without showing a Dialog.
}

{
  Dieses Beispiel zeigt, wie man lokale Dateien in einem TWebbrowser 
  öffnen kann und wie man lokale Links direct ausführen kann ohne
  dass ein Dialog erscheint.
}


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure WebBrowser1BeforeNavigate2(Sender: TObject;
      const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
      Headers: OleVariant; var Cancel: WordBool);
  private
    FIsStartPage: Boolean;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

uses
  ShellApi;


// Open a local page:
procedure TForm1.Button1Click(Sender: TObject);
const
 LOCAL_PAGE ='C:/StartPage.htm'
begin
  FIsStartPage := True;
  Webbrowser1.Navigate('file:///' + LOCAL_PAGE);
  FIsStartPage := False;
end;


procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
var
  newURL: string;
begin
  newURL := URL;
  // For local links, don't show a dialog but open the file directly
  if (not FIsStartPage) and FileExists(newURL) then
  begin
    Cancel := True;
    ShellExecute(Application.Handle, 'open', PChar(newURL), nil, nil, 
SW_NORMAL);
  end;
end;




Best Regards
SwissDelphiCenter Team
www.swissdelphicenter.ch
[automatic generated EMail]

Other related posts:

  • » New Tip - ...open local files in a TWebbrowser and start links directly ?