VC++ 多线程模拟鼠标点击

HANDLE handle = CreateThread(NULL, 0, ThreadFun, NULL, 0, NULL);

 

DWORD WINAPI ThreadFun(LPVOID pM)
{
  // 休眠一下让 CShowSealistDlg 窗体显示出来
  ::Sleep(200);
  // 记录当前鼠标位置
  CPoint point;
  GetCursorPos(&point);
  //计算要点击的位置,将像素坐标转换鼠标能认识的坐标
  DWORD dx = 2 * 65536 / GetSystemMetrics(SM_CXSCREEN);
  DWORD dy = 2 * 65536 / GetSystemMetrics(SM_CYSCREEN);
  //移动鼠标,模拟点击鼠标左键
  mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP,
    dx, dy, 0, GetMessageExtraInfo());
  //恢复鼠标到原来的位置
  SetCursorPos(point.x, point.y);

  return 0;
}

你可能感兴趣的:(vc++)