a、鼠拟鼠标单击mouse_event
b、鼠标指针移动还原
HWND gameh;//游戏窗口句柄RECT r1;//RECT结构表示一个矩形区域POINT p;//x,yvoid CFewDlg::OnStartGame(){ gameh=::FindWindow(NULL,"井字棋"); ::GetWindowRect(gameh,&r1); GetCursorPos(&p);//保存当前鼠标指针 //取得当前鼠标位置 SetCursorPos(100+r1.left,100+r1.top);//当前窗口坐标+开局按钮坐标 this->m_x=r1.left; this->m_y=r1.top; UpdateData(false);//显示到编辑框 mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0);//鼠标在当前位置按下 mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0);//鼠标在当前位置抬起 mouse_event(MOUSEEVENTF_LEFTUP,0,0,0,0); Sleep(200);//过一段时间 再执行后边的代码 SetCursorPos(p.x,p.y); //还原鼠标位置}void CFewDlg::OnButton1() { OnStartGame();}
MFC框架构造请看[外挂1]