unit webbrower;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
WebBrowser2: TWebBrowser;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure WebBrowser1NewWindow2(Sender: TObject; var ppDisp: IDispatch;
var Cancel: WordBool);
procedure WebBrowser2BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses Activex;
const
OLECMDID_OPTICAL_ZOOM = 63;
procedure TForm1.Button1Click(Sender: TObject);
begin
Webbrowser1.Navigate('http:\\www.hao123.com') ;
end;
procedure TForm1.WebBrowser1NewWindow2(Sender: TObject;
var ppDisp: IDispatch; var Cancel: WordBool);
begin
ppDisp := Webbrowser2.Application;
end;
procedure TForm1.WebBrowser2BeforeNavigate2(Sender: TObject;
const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
Headers: OleVariant; var Cancel: WordBool);
begin
WebBrowser1.Navigate(string(URL)); // 再指回WebBrowser1
Cancel := True
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
WebBrowser1.GoBack;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
ZoomIn: OleVariant;
begin
ZoomIn := 150;
//WebBrowser1.ExecWB(OLECMDID_OPTICAL_ZOOM, OLECMDEXECOPT_DODEFAULT, ZoomIn); // TWebBrowser 調(diào)用的是 IE, 放縮頁(yè)面是在 IE7 之后才支持的.
WebBrowser1.ExecWB(OLECMDID_PAGESETUP, OLECMDEXECOPT_DODEFAULT, EmptyParam, EmptyParam); //打印頁(yè)面設(shè)置
end;
initialization
oleinitialize(nil);
finalization
oleuninitialize;
end.