鼠标连点器

//快捷键开启关闭连点器
void
CmouseClickDlg::OnHotKey( UINT uMsg, UINT wParam, UINT lParam ) { if(!m_canClick) { CString str; m_txtTime.GetWindowText(str); m_interval = atoi(str); m_pWindowTimer = SetTimer(0, m_interval, NULL); m_canClick = true; } else { m_canClick = false; KillTimer(m_pWindowTimer); } }
//timer回调模拟点击
void
CmouseClickDlg::OnTimer( UINT nIDEvent ) { if(!m_canClick) return; static int lasttick = 0; if (lasttick == 0) { lasttick = GetTickCount(); } TRACE("TIME: %d\r\n", GetTickCount()-lasttick); lasttick = GetTickCount(); CPoint pt; GetCursorPos(&pt); CWnd* pWnd = WindowFromPoint(pt); HWND hWnd = pWnd->GetSafeHwnd(); if(!hWnd) { MessageBox(_T("获取句柄失败")); return; } DWORD dwPId = 0; ::GetWindowThreadProcessId(hWnd, &dwPId); if(!dwPId) { MessageBox(_T("获取PID失败")); return; } ::ScreenToClient(hWnd, &pt); DWORD para = pt.y << 16 | pt.x; ::PostMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, para); ::PostMessage(hWnd, WM_LBUTTONUP, MK_LBUTTON, para); }

下载源码

猜你喜欢

转载自www.cnblogs.com/barrysgy/p/10346182.html
今日推荐