日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

Qt-捕获Windows消息

發布時間:2023/12/18 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Qt-捕获Windows消息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Qt4版本的實現
方法1:
通過繼承QWidget的類中重新實現winEvent接口,以接收在消息參數中傳遞的本機Windows事件。
bool QWidget::winEvent(MSG *message, long *result)
1
方法2:
通過繼承QCoreApplication的類中重新實現winEventFilter接口,以接收在消息參數中傳遞的本機Windows事件。
bool QCoreApplication::winEventFilter(MSG *msg, long *result)
1
Qt5版本實現
方法1:
通過繼承QWidget的類中重新實現winEvent接口,以接收在消息參數中傳遞的eventType標識的本機平臺事件。
bool QWidget::nativeEvent(const QByteArray &eventType, void *message, long *result)
1
方法2:
通過繼承QAbstractNativeEventFilter的類中重新實現nativeEventFilter接口:
bool QAbstractNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
1
并安裝到中:

void QCoreApplication::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
1
或安裝到:

void QAbstractEventDispatcher::installNativeEventFilter(QAbstractNativeEventFilter *filterObj)
1
特別地:不同平臺對應的eventType類型有:
平臺? ? ? ? ? ? ? ? 事件類型(eventType)? ? ? ? ? ? 消息類型(message)? ? ? ? ?結果類型(result)
Windows? ? ? ? “windows_generic_MSG”? ? ? MSG *? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LRESULT
macOs? ? ? ? ? ?“NSEvent”? ? ? ? ? ? ? ? ? ? ? ? ? ? ? NSEvent *? ? ? ? ? ? ? ? ? ? ? ? 無
XCB(Linux)?? ?“xcb_generic_event_t”? ? ? ? ? ?xcb_generic_event_t *? ? ?無

/******************************************************

繼承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);
?

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的Qt-捕获Windows消息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。