学习用IsChild(WebBrowser1.Handle, Msg.Hwnd)判断鼠标事件是否来自TWebBrowser
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, StdCtrls, MSHTML;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
procedure FormCreate(Sender: TObject);
procedure WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
private
{ Private declarations }
FLoaded: Boolean;
procedure AppMsg(var Msg: TagMsg; var Handled: Boolean);
procedure GetContronl;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.AppMsg(var Msg: TagMsg; var Handled: Boolean);
var
mPoint : TPoint;
begin
if IsChild(WebBrowser1.Handle, Msg.Hwnd) and
(Msg.Message = WM_MOUSEMOVE) and FLoaded then
begin
GetCursorPos(mPoint);
GetContronl;
//PopupMenu1.Popup(mPoint.X, mPoint.Y);
Handled:=True;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
FLoaded := False;
WebBrowser1.Navigate( 'http://www.kitop.com ');
Application.OnMessage := AppMsg;
end;
procedure TForm1.GetContronl;
var
E: IHTMLElement;
tmpStr: String;
myPoint: TPoint;
begin
myPoint := Mouse.CursorPos;
myPoint := WebBrowser1.ScreenToClient(myPoint);
{
myPoint.X := myPoint.X + 100;
myPoint.Y := myPoint.Y + 100;
}
E := (WebBrowser1.Document as IHTMLDocument2).elementFromPoint(myPoint.X, myPoint.Y);
//E := (WebBrowser1.Document as IHTMLDocument2).elementFromPoint(100, 100);
//ShowMessage(E.title);
tmpStr := Format( '%s,%s,%s,%s;X:%d;Y:%d ',[E.className,E.id,E.tagName,E.innerHTML,
myPoint.X,myPoint.Y]);
Caption := tmpStr;
end;
procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
FLoaded := True;
end;
end.
转自:http://t.zoukankan.com/delphi7456-p-1896632.html
标签:WebBrowser1,myPoint,鼠标,TForm1,TWebBrowser,添加,var,end,procedure From: https://www.cnblogs.com/tang-delphi/p/16751517.html