delphi 怎么在WebBrowser控件里获得光标的位置
delphi在在WebBrowser控件里面怎么获得光标的具体位置,在窗口的位置也行,在屏幕的位置也可以...
delphi 在在WebBrowser控件里面怎么获得光标的具体位置,在窗口的位置也行,在屏幕的位置也可以
展开
展开全部
网上借鉴的,思路如下
WebBrowser没有mouseMove事件,但它还是由WinControl继承下来的,所以有窗体handle,自定义一个win消息捕获来自此handle的鼠标移动
use MSHTML;
private
{ Private declarations }
FLoaded: Boolean;
procedure AppMsg(var Msg: TagMsg; var Handled: Boolean);
procedure GetContronl;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
FLoaded:=False;
Application.OnMessage := AppMsg;
wb1.Navigate('about:<head><title>标题></title><body>页面内容</body>');
end;
procedure TForm1.wb1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
FLoaded:=True;
end;
procedure TForm1.AppMsg(var Msg: TagMsg; var Handled: Boolean);
var
mPoint : TPoint;
begin
if IsChild(wb1.Handle, Msg.Hwnd) and
(Msg.Message = WM_MOUSEMOVE) and FLoaded then
begin
GetCursorPos(mPoint);
Caption:=IntToStr(mPoint.X);
GetContronl;
Handled:=True;
end;
end;
procedure TForm1.GetContronl;
var
myPoint: TPoint;
begin
//myPoint := Mouse.CursorPos;
myPoint := wb1.ScreenToClient(myPoint);
Caption := IntToStr(myPoint.X)+'+'+IntToStr(myPoint.Y);
end;
WebBrowser没有mouseMove事件,但它还是由WinControl继承下来的,所以有窗体handle,自定义一个win消息捕获来自此handle的鼠标移动
use MSHTML;
private
{ Private declarations }
FLoaded: Boolean;
procedure AppMsg(var Msg: TagMsg; var Handled: Boolean);
procedure GetContronl;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
FLoaded:=False;
Application.OnMessage := AppMsg;
wb1.Navigate('about:<head><title>标题></title><body>页面内容</body>');
end;
procedure TForm1.wb1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
FLoaded:=True;
end;
procedure TForm1.AppMsg(var Msg: TagMsg; var Handled: Boolean);
var
mPoint : TPoint;
begin
if IsChild(wb1.Handle, Msg.Hwnd) and
(Msg.Message = WM_MOUSEMOVE) and FLoaded then
begin
GetCursorPos(mPoint);
Caption:=IntToStr(mPoint.X);
GetContronl;
Handled:=True;
end;
end;
procedure TForm1.GetContronl;
var
myPoint: TPoint;
begin
//myPoint := Mouse.CursorPos;
myPoint := wb1.ScreenToClient(myPoint);
Caption := IntToStr(myPoint.X)+'+'+IntToStr(myPoint.Y);
end;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询