qt捕获全局windows消息(使用QAbstractNativeEventFilter,然后注册这个类)

首先是让你自己的类继承自QAbstractNativeEventFilter,然后通过QCoreApplication来注册你的窗口类,代码如下:
app.installNativeEventFilter(m_MainWindow);
          最后在nativeEventFilter方法中就能获取到系统级事件,我的qt5.5.观看qt的帮助文档,如图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所示

猜你喜欢

转载自blog.csdn.net/lengyuezuixue/article/details/81078961
今日推荐