MFC怎么向其他窗口发送消息? 我是想模拟按键精灵的功能.为什么用SendMessage没用? 20
Sleep(5000);//ddddCWnd*pWnd=GetForegroundWindow();//CWnd*pWnd=GetDesktopWindow();pWnd...
Sleep (5000);//dddd
CWnd *pWnd = GetForegroundWindow();
//CWnd *pWnd = GetDesktopWindow();
pWnd->PostMessage (WM_LBUTTONDOWN, 0, LOWORD (1570) | HIWORD (5));
SetCursorPos(1570, 5);
Sleep(100);
pWnd->PostMessage (WM_LBUTTONUP, 0, LOWORD (1570) | HIWORD (5));
这是想让它往关闭窗口发送一对鼠标按下, 弹起的消息, 但是没有用. 展开
CWnd *pWnd = GetForegroundWindow();
//CWnd *pWnd = GetDesktopWindow();
pWnd->PostMessage (WM_LBUTTONDOWN, 0, LOWORD (1570) | HIWORD (5));
SetCursorPos(1570, 5);
Sleep(100);
pWnd->PostMessage (WM_LBUTTONUP, 0, LOWORD (1570) | HIWORD (5));
这是想让它往关闭窗口发送一对鼠标按下, 弹起的消息, 但是没有用. 展开
展开全部
SetCursorPos用的不对,这个必须是鼠标在当前进程窗口内才有效。
这样试试:
CWnd *pWnd = GetForegroundWindow();
HWND hWnd = pWnd->GetSafeHandle();
DWORD pos = MAKELPARAM(1570, 5);
PostMessage(m_hWnd, WM_MOUSEMOVE, 0, pos);
Sleep(100);
PostMessage(m_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, pos);
Sleep(50);
PostMessage(m_hWnd, WM_LBUTTONUP, 0, pos);
Sleep(100);
更多追问追答
追问
我让它移动鼠标只是为了看看我写的坐标对不对, 只要把鼠标按下的消息发过去不就行了?
而且你这代码也不对........不过能看懂.........
那个不明白的就是, 为什么要发送鼠标移动的消息, 和为什么要调用;GetSafeHandle, 发送鼠标按下消息的时候为什么要写wParam?
你的这个代码还没测试, 不知道对不对呢.
追答
CWnd *pWnd = GetForegroundWindow();
HWND hWnd = pWnd->GetSafeHwnd();
DWORD pos = MAKELPARAM(1570, 5);
::PostMessage(m_hWnd, WM_MOUSEMOVE, 0, pos);
Sleep(100);
::PostMessage(m_hWnd, WM_LBUTTONDOWN, MK_LBUTTON, pos);
Sleep(50);
::PostMessage(m_hWnd, WM_LBUTTONUP, 0, pos);
Sleep(100);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询