unit Cweb2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, ActiveX;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure DemoEventSink(Sender: TObject);
private
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
uses MSHTML, IEDocHostUIHandler, IEConst, DHTMLEvent,comobj;
var
FDocHostUIHandler: TDocHostUIHandler;//为屏蔽右键菜单
Doc : IHTMLDocument2;
Element : IHTMLElement;
EventSink: TDHTMLEvent;
procedure TForm1.FormCreate(Sender: TObject);
begin
FDocHostUIHandler := TDocHostUIHandler.Create;//为屏蔽右键菜单
EventSink := TDHTMLEvent.Create;
WebBrowser1.Navigate(GetCurrentDir + '/index.htm');
end;
procedure TForm1.DemoEventSink(Sender: TObject);
Var
S:String;
begin
S:='B0';
Element:=Doc.all.item(S, 0) as IHTMLElement;
if nil<>Element then
Begin
Element.style.color:='#ff0000';
ShowMessage('您的鼠标单击了第一行文字!');
end;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
S:String;
Connection,i:integer;
begin
Doc := IHTMLDocument2(WebBrowser1.Document);
InterfaceConnect(Doc, HTMLDocumentEvents2, EventSink, Connection);
end;
end.