15,976
社区成员
发帖
与我相关
我的任务
分享
CWnd::FromHandle(hWnd)->ShowWindow(SW_NORMAL);
CWnd::FromHandle(hWnd)->SetForegroundWindow();
SetCursorPos(ptPointA.x, ptPointA.y);
strLogs.Format("移动鼠标到点A!");
WriteLog(strLogs, 1);
// 鼠标右击
// 使用SendMessage的话可以看到编辑框内鼠标在闪,我想是因为上面的SetCursorPos的缘故
// 但是似乎由于SetCursorPos把焦点定到编辑框后,下面的SendMessage马上又把焦点拉出去了,这是为什么呢?
//::SendMessage(hWnd, WM_RBUTTONDOWN, NULL, NULL);
//::SendMessage(hWnd, WM_RBUTTONUP, NULL, NULL);
mouse_event(MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0);//点下右键
mouse_event(MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0);//松开右键
strLogs.Format("鼠标右击!");
WriteLog(strLogs, 1);
Sleep(10);
SetCursorPos(ptPointB.x, ptPointB.y);
strLogs.Format("移动鼠标到点B");
WriteLog(strLogs, 1);
Sleep(10);
// 鼠标左击
//::SendMessage(hWnd, WM_LBUTTONDOWN, NULL, NULL);
//::SendMessage(hWnd, WM_LBUTTONUP, NULL, NULL);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);//点下左键
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);//松开左键
strLogs.Format("鼠标左击");
WriteLog(strLogs, 1);
Sleep(10);
// 空格
//::SendMessage(hWnd, WM_KEYDOWN, VK_SPACE, NULL);
keybd_event(VK_SPACE, 0, 0, 0);
keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
strLogs.Format("按下空格");
WriteLog(strLogs, 1);
Sleep(1000);
strLogs.Format("继续循环!");
WriteLog(strLogs, 1);
strLogs.Format("=======================================");
WriteLog(strLogs, 1);
HWND hWnd = ::FindWindow(_T("Notepad"), NULL);
if(NULL == hWnd)
{
return ;
}
HWND hEdit = ::FindWindowEx(hWnd, NULL, _T("Edit"), NULL);
if(NULL != hEdit)
{
CRect rect;
::GetWindowRect(hEdit, &rect);
CPoint pt = rect.CenterPoint();
::PostMessage(hEdit, WM_CONTEXTMENU, (WPARAM)hEdit, MAKELPARAM(pt.x, pt.y));
}