Qt捕獲Windows消息

繼承Qt的基類QAbstractNativeEventFilter

class HHNativeEventFilter : public QAbstractNativeEventFilter
{
protected:
    bool nativeEventFilter(const QByteArray &eventType, void *message, long *)
    {
        if (eventType == "windows_generic_MSG"
                || eventType == "windows_dispatcher_MSG")
        {
            PMSG msg = static_cast<PMSG>(message);
            if(msg->message == WM_CLOSE )
            {
                qApp->exit();
            }
        }
        return false;
    }
};

利用QApplication註冊類對象

app.installNativeEventFilter(new NativeEventFilter);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章