怎样获得当前鼠标所在位置的窗口句柄,该怎么解决

 我来答
ty...c@163.com
2016-12-25 · TA获得超过418个赞
知道小有建树答主
回答量:918
采纳率:83%
帮助的人:431万
展开全部
#include <windows.h>
int main()
{
while (1)
{
POINT pNow = {0,0};
if (GetCursorPos(&pNow)) // 获取鼠标当前位置
{
HWND hwndPointNow = NULL;
hwndPointNow = WindowFromPoint(pNow); // 获取鼠标所在窗口的句柄
if (hwndPointNow)
{
//cout << "Success!!" << endl;
char szWindowTitle[50];
::GetWindowTextA(hwndPointNow, szWindowTitle, sizeof(szWindowTitle)); // 获取窗口标题
cout << hex << (int)hwndPointNow << endl; // 鼠标所在窗口的句柄
cout << szWindowTitle << endl; // 鼠标所在窗口的标题
}
else
cout << "Error!!" << endl;
}
else
cout << "Error!!" << endl;
Sleep(500);
}
return 0;
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式