获取鼠标所在窗体的PID

来源:互联网 发布:冷情阁app网络错误 编辑:程序博客网 时间:2024/06/05 16:41
#include <Windows.h>#include <iostream>using namespace std;DWORD GetPIDFromCursor(void){POINT CursorPos;//获取当前鼠标的位置if (!GetCursorPos(&CursorPos)){cout << "GetCursorPos Error: " << GetLastError() << endl;return 0;}//从鼠标位置获取当前窗体的句柄HWND hWnd = WindowFromPoint(CursorPos);if (NULL == hWnd){cout << "No window exists at the given point!" << endl;return 0;}//获取窗体句柄的pidDWORD dwProcId;GetWindowThreadProcessId(hWnd, &dwProcId);return dwProcId;}int main(){int pid=GetPIDFromCursor();cout<<pid<<endl;return 0;}

0 0
原创粉丝点击