我想任意用鼠标获取一个外部程序控件或窗体句柄,然后返回句柄所指的控件或窗体高底及位置,这该如何实现?
var po:tpoint;
wnd:hwnd;
begin
getcursorpos(po) ;//获得鼠标坐标
wnd:=windowFromPoint(po);//通过鼠标获得所在窗口句柄
///然后我要得到控件大小,怎么做?

解决方案 »

  1.   

    The GetWindowRect function retrieves the dimensions of the bounding rectangle of the specified window. The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen. BOOL GetWindowRect(    HWND hWnd, // handle of window
        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 
      

  2.   

    同意  outer2000(天外流星) 
    继续你的 代码
    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;
      

  3.   

    多谢两位大哥帮助,我已经实现我的程序了,我叫它ZNZN(指哪抓哪),包括菜单,可以选区域,选窗体,选dbgrid。还能选什么我正试着那,咳,说了这么多,忘了结贴发分了,我这就结,呵呵