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中的鼠标就没有一定效果,为什么?
我在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中的鼠标就没有一定效果,为什么?
::SendMessage(m_hwndCtrlMain,WM_MOUSEMOVE,0,dwPos)则不会。
就是说mouse_event()会影响我其它应用程序,而::SendMessage(m_hwndCtrlMain,WM_MOUSEMOVE,0,dwPos)就像后台操作一样。
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);
B进程的m_hwndCtrlMain窗口的Button不起作用。
你如果不一定要得到执行结果的话我想还是用::PostMessage()比较好!
HWND hwnd = ::FindWindowEx(NULL,NULL,"那个窗口名",NULL);
HWND hbtn = ::FindWindowEx(hwnd,hbtn,"按钮名",NULL);
得到 broadoceans(broadoceans)的一些启发。
先移动,让后发,发的时候将状态参数设上:MK_LBUTTON
这样就好了,估计这样才是完全模拟了Windows的动作。
谢谢大家。