m_hwndCtrlMain是B进程的某个窗口HWND。
我在A进程中,做:
DWORD dwPos=MAKELONG(m_pt.x,m_pt.y);
::SendMessage(m_hwndCtrlMain,WM_MOUSEMOVE,0,dwPos); 
此消息发出后,m_hwndCtrlMain中的鼠标的确移动了。
但是,我再做:
::SendMessage(m_hwndCtrlMain,WM_LBUTTONDOWN,0,dwPos); 
::SendMessage(m_hwndCtrlMain,WM_LBUTTONUP,0,dwPos); 
m_hwndCtrlMain中的鼠标就没有一定效果,为什么?

解决方案 »

  1.   

    mouse_event()会引起让我鼠标跑过去,而且那个位置是其它程序则作用到其它程序上了。
    ::SendMessage(m_hwndCtrlMain,WM_MOUSEMOVE,0,dwPos)则不会。
    就是说mouse_event()会影响我其它应用程序,而::SendMessage(m_hwndCtrlMain,WM_MOUSEMOVE,0,dwPos)就像后台操作一样。
      

  2.   

    WM_LBUTTONDOWN
    The WM_LBUTTONDOWN message is posted when the user presses the left mouse button while the cursor is in the client area of a window. If the mouse is not captured, the message is posted to the window beneath the cursor. Otherwise, the message is posted to the window that has captured the mouse.所以你应该先移动,然后::SendMessage(m_hwndCtrlMain,WM_LBUTTONDOWN,0,dwPos); 
      

  3.   

    而且mouse_event()也不其作用,鼠标跑到了m_hwndCtrlMain窗口的Button上,可就是没有按下
      

  4.   

    上面说错了,mouse_event()对其它的有用,可偏偏对
    B进程的m_hwndCtrlMain窗口的Button不起作用。
      

  5.   

    如果是btn的话你只要给button发送NM_CLICK消息就可以了
      

  6.   

    同意楼上的!
    你如果不一定要得到执行结果的话我想还是用::PostMessage()比较好!
      

  7.   

    问题是我无法得到其按钮的hand啊。
      

  8.   

    能得到那个窗口的名柄么?
    HWND hwnd = ::FindWindowEx(NULL,NULL,"那个窗口名",NULL);
    HWND hbtn = ::FindWindowEx(hwnd,hbtn,"按钮名",NULL);
      

  9.   

    窗口得到了,按钮得不到。呵呵。
    得到 broadoceans(broadoceans)的一些启发。
    先移动,让后发,发的时候将状态参数设上:MK_LBUTTON
    这样就好了,估计这样才是完全模拟了Windows的动作。
    谢谢大家。