您的位置:首页 > 编程语言 > Qt开发

qt捕获全局windows消息

2016-07-01 13:41 567 查看
qt 如何捕获全屏的鼠标事件,这个帖子上面主要讲述了下嵌入式qt怎么抓取系统级消息,不过从这篇文章中我也看到了希望,有个回复说winEventFilter支持这种方式,然后我就顺着这个线索找到了nativeEventFilter方法,最终试验成功。

首先是让你自己的类继承自QAbstractNativeEventFilter,然后通过QCoreApplication来注册你的窗口类,代码如下:
app.installNativeEventFilter(m_MainWindow);

最后在nativeEventFilter方法中就能获取到系统级事件,我的qt5.5.观看qt的帮助文档,如图1所示



图1

bool CCailianMainWindow::nativeEventFilter(const QByteArray & eventType, void * message, long * result)
{
if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG")
{
MSG * pMsg = reinterpret_cast<MSG *>(message);

if (pMsg->message == WM_NCMOUSEMOVE)
{
//获取到系统鼠标移动,可以做像qq一样的忙碌检测
}
}

return false;
}

调试结果如图2所示



图2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: