请问如何获取指定窗口的坐标
然后再用Mouse Event 点击该窗口的指定位置该如何实现.
本人菜鸟希望有高手能发代码上来供测试.

解决方案 »

  1.   

    鼠标自动点击的例子,模拟鼠标点击 
    procedure TForm1.Button1Click(Sender: TObject);
    var
    x,y:integer;
    begin
    x:= form1.Left+button2.Left+25;
    y:= top+button2.Top+27;
    SetCursorPos(x,y);
    Mouse_Event(MOUSEEVENTF_LEFTDOWN,X,Y,0,0);
    Mouse_Event(MOUSEEVENTF_LEFTUP,X,Y,0,0);
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
    showmessage('fksj');
    end;
    *************************************
    // Set the mouse cursor to position x,y:
    SetCursorPos(x, y);
    // Simulate the left mouse button down
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    // Simulate the right mouse button down
    mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);
      

  2.   

    可使用 API 取得窗体坐标
    BOOL GetWindowRect(
      HWND hWnd,      // handle to window
      LPRECT lpRect   // address of structure for window coordinates
    );
      

  3.   

    1楼的那个是非常的好,不过那个只是自己程序的窗体,现在要点击的是外部程序的窗体,如果是外一程序,代码应该怎么实现呢,可以用到API,小弟不懂,希望贴出代码能带注释.小的感激不尽.
      

  4.   

    点取外部窗体肯定要获取窗体句柄了,FindWindow。
      

  5.   

    var
      P: TPoint;
      R: TRect;
    begin
      if Windows.GetClientRect(H, R) then  //获取客户区大小,不含标题栏及边框
      begin
        P := R.TopLeft;  //取左上角
        Windows.ClientToScreen(H, P);  //转换成屏幕坐标
        OffsetRect(R, P.X, P.Y);  //移动Rect,相当于转换成屏幕坐标
      end; 
    end;