我想任意用鼠标获取一个外部程序控件或窗体句柄,然后返回句柄所指的控件或窗体高底及位置,这该如何实现?
var po:tpoint;
wnd:hwnd;
begin
getcursorpos(po) ;//获得鼠标坐标
wnd:=windowFromPoint(po);//通过鼠标获得所在窗口句柄
///然后我要得到控件大小,怎么做?
var po:tpoint;
wnd:hwnd;
begin
getcursorpos(po) ;//获得鼠标坐标
wnd:=windowFromPoint(po);//通过鼠标获得所在窗口句柄
///然后我要得到控件大小,怎么做?
LPRECT lpRect // address of structure for window coordinates
);
ParametershWndIdentifies the window. lpRectPoints to a RECT structure that receives the screen coordinates of the upper-left and lower-right corners of the window. Return ValuesIf the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. See AlsoGetClientRect, RECT
继续你的 代码
var po:tpoint;
wnd:hwnd;
rect:Trect;
begin
getcursorpos(po) ;//获得鼠标坐标
wnd:=windowFromPoint(po);//通过鼠标获得所在窗口句柄
GetWindowRect(wnd,rect);
showmessage('左:'+inttostr(rect.Left)+#13+'顶:'+inttostr(rect.Top)+#13+'右:'+inttostr(rect.Right)+#13+'底:'+inttostr(rect.Bottom));
showmessage('高='+inttostr(rect.Bottom-rect.Top)+#13+'宽='+inttostr(rect.Right-rect.Left));
end;