S
su_sh
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, OleCtrls, SHDocVw, ImgList,Registry,MSHTML,ActiveX;
type
TBrowser = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
WebBrowser: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure WebBrowserNewWindow2(Sender: TObject; var ppDisp: IDispatch;
var Cancel: WordBool);
procedure WebBrowserDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
TS: TTabSheet;
WB: TWebBrowser;
WBDocumentComplete: TWebBrowserDocumentComplete; //为生成页面标题的过程
WBNewWindow2 : TWebBrowserNewWindow2;
//WBTitleChange : TWebBrowserTitleChange;
//WBStatusTextChange : TWebBrowserStatusTextChange;
//WBProgressChange : TWebBrowserProgressChange;
//WBBeforeNavigate2:TWebBrowserBeforeNavigate2;
public
{ Public declarations }
end;
var
Browser: TBrowser;
implementation
{$R *.dfm}
procedure TBrowser.FormCreate(Sender: TObject);
var
OUrl: OleVariant;
begin
OUrl := 'about:blank';
WebBrowser.Navigate2(OUrl);
WBDocumentComplete := WebBrowser.OnDocumentComplete;
WBNewWindow2 := WebBrowser.OnNewWindow2;
//WBTitleChange := WebBrowser.OnTitleChange;
//WBStatusTextChange := WebBrowser.OnStatusTextChange;
//WBProgressChange := WebBrowser.OnProgressChange;
//WBBeforeNavigate2 := WebBrowser.OnBeforeNavigate2;
//WBDocumentComplete := WebBrowser.OnDocumentComplete;
if Assigned(TabSheet1) then
TabSheet1.Destroy;
{========多页面部分=======}
TS := TTabSheet.Create(nil);
TS.PageControl := PageControl1;
TS.Align:=alClient;
WB := TWebBrowser.Create(nil);
TS.InsertControl(WB);
WB.ParentWindow:=PageControl1.Pages[PageControl1.PageCount-1].Handle;
WB.TheaterMode:=true;
WB.RegisterAsBrowser;
WB.Align := alClient;
PageControl1.ActivePage := TS;
WB.Navigate('www.baidu.com');
WB.Show;
//WBDocumentComplete := WebBrowser.OnDocumentComplete;
WB.OnDocumentComplete := WBDocumentComplete;
WB.OnNewWindow2 := WBNewWindow2;
//WB.OnTitleChange:= WBTitleChange;
//WB.OnStatusTextChange:=WBStatusTextChange;
//WB.OnProgressChange:=WBProgressChange;
//WB.OnBeforeNavigate2:=WBBeforeNavigate2;
//WB.OnDocumentComplete := WBDocumentComplete;
end;
procedure TBrowser.WebBrowserNewWindow2(Sender: TObject;
var ppDisp: IDispatch; var Cancel: WordBool);
begin
if Assigned(TabSheet1) then
TabSheet1.Destroy;
{========多页面部分=======}
TS := TTabSheet.Create(nil);
TS.PageControl := PageControl1;
TS.Align:=alClient;
WB := TWebBrowser.Create(nil);
TS.InsertControl(WB);
WB.ParentWindow:=PageControl1.Pages[PageControl1.PageCount-1].Handle;
WB.TheaterMode:=true;
WB.RegisterAsBrowser;
WB.Align := alClient;
PageControl1.ActivePage := TS;
ppDisp := WB.Application;
WB.Show;
//WBDocumentComplete := WebBrowser.OnDocumentComplete;
WB.OnDocumentComplete := WBDocumentComplete;
WB.OnNewWindow2 := WBNewWindow2;
//WB.OnTitleChange:= WBTitleChange;
//WB.OnStatusTextChange:=WBStatusTextChange;
//WB.OnProgressChange:=WBProgressChange;
//WB.OnBeforeNavigate2:=WBBeforeNavigate2;
//WB.OnDocumentComplete := WBDocumentComplete;
end;
procedure TBrowser.WebBrowserDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
Doc : IHTMLDocument2;
begin
Doc := WB.Document as IHtmlDocument2;
if Assigned(WB) and assigned(WB.Document) then
begin
if length(Doc.title)>20 then
TS.Caption:=copy(Doc.title,0,20)+'......'
else
TS.Caption:=IHtmlDocument2(WB.Document).title;
end;
end;
initialization
{ TODO : 引进了TRegistry类,WebBrowser是OLE对象,需要对它初始化 }
OleInitialize(nil);
finalization
try
OleUninitialize;
except
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, OleCtrls, SHDocVw, ImgList,Registry,MSHTML,ActiveX;
type
TBrowser = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
WebBrowser: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure WebBrowserNewWindow2(Sender: TObject; var ppDisp: IDispatch;
var Cancel: WordBool);
procedure WebBrowserDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
TS: TTabSheet;
WB: TWebBrowser;
WBDocumentComplete: TWebBrowserDocumentComplete; //为生成页面标题的过程
WBNewWindow2 : TWebBrowserNewWindow2;
//WBTitleChange : TWebBrowserTitleChange;
//WBStatusTextChange : TWebBrowserStatusTextChange;
//WBProgressChange : TWebBrowserProgressChange;
//WBBeforeNavigate2:TWebBrowserBeforeNavigate2;
public
{ Public declarations }
end;
var
Browser: TBrowser;
implementation
{$R *.dfm}
procedure TBrowser.FormCreate(Sender: TObject);
var
OUrl: OleVariant;
begin
OUrl := 'about:blank';
WebBrowser.Navigate2(OUrl);
WBDocumentComplete := WebBrowser.OnDocumentComplete;
WBNewWindow2 := WebBrowser.OnNewWindow2;
//WBTitleChange := WebBrowser.OnTitleChange;
//WBStatusTextChange := WebBrowser.OnStatusTextChange;
//WBProgressChange := WebBrowser.OnProgressChange;
//WBBeforeNavigate2 := WebBrowser.OnBeforeNavigate2;
//WBDocumentComplete := WebBrowser.OnDocumentComplete;
if Assigned(TabSheet1) then
TabSheet1.Destroy;
{========多页面部分=======}
TS := TTabSheet.Create(nil);
TS.PageControl := PageControl1;
TS.Align:=alClient;
WB := TWebBrowser.Create(nil);
TS.InsertControl(WB);
WB.ParentWindow:=PageControl1.Pages[PageControl1.PageCount-1].Handle;
WB.TheaterMode:=true;
WB.RegisterAsBrowser;
WB.Align := alClient;
PageControl1.ActivePage := TS;
WB.Navigate('www.baidu.com');
WB.Show;
//WBDocumentComplete := WebBrowser.OnDocumentComplete;
WB.OnDocumentComplete := WBDocumentComplete;
WB.OnNewWindow2 := WBNewWindow2;
//WB.OnTitleChange:= WBTitleChange;
//WB.OnStatusTextChange:=WBStatusTextChange;
//WB.OnProgressChange:=WBProgressChange;
//WB.OnBeforeNavigate2:=WBBeforeNavigate2;
//WB.OnDocumentComplete := WBDocumentComplete;
end;
procedure TBrowser.WebBrowserNewWindow2(Sender: TObject;
var ppDisp: IDispatch; var Cancel: WordBool);
begin
if Assigned(TabSheet1) then
TabSheet1.Destroy;
{========多页面部分=======}
TS := TTabSheet.Create(nil);
TS.PageControl := PageControl1;
TS.Align:=alClient;
WB := TWebBrowser.Create(nil);
TS.InsertControl(WB);
WB.ParentWindow:=PageControl1.Pages[PageControl1.PageCount-1].Handle;
WB.TheaterMode:=true;
WB.RegisterAsBrowser;
WB.Align := alClient;
PageControl1.ActivePage := TS;
ppDisp := WB.Application;
WB.Show;
//WBDocumentComplete := WebBrowser.OnDocumentComplete;
WB.OnDocumentComplete := WBDocumentComplete;
WB.OnNewWindow2 := WBNewWindow2;
//WB.OnTitleChange:= WBTitleChange;
//WB.OnStatusTextChange:=WBStatusTextChange;
//WB.OnProgressChange:=WBProgressChange;
//WB.OnBeforeNavigate2:=WBBeforeNavigate2;
//WB.OnDocumentComplete := WBDocumentComplete;
end;
procedure TBrowser.WebBrowserDocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
Doc : IHTMLDocument2;
begin
Doc := WB.Document as IHtmlDocument2;
if Assigned(WB) and assigned(WB.Document) then
begin
if length(Doc.title)>20 then
TS.Caption:=copy(Doc.title,0,20)+'......'
else
TS.Caption:=IHtmlDocument2(WB.Document).title;
end;
end;
initialization
{ TODO : 引进了TRegistry类,WebBrowser是OLE对象,需要对它初始化 }
OleInitialize(nil);
finalization
try
OleUninitialize;
except
end;
end.