qt捕获全局windows消息
标签:als public vat null patch xpl 全局 gen clu
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include
#include namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow,public QAbstractNativeEventFilter
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#pragma comment(lib, "user32.lib")
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::nativeEventFilter(const QByteArray & eventType, void * message, long * result)
{
if (eventType == "windows_generic_MSG" || eventType == "windows_dispatcher_MSG")
{
MSG * pMsg = reinterpret_cast(message);
if (pMsg->message == WM_NCMOUSEMOVE)
{
//获取到系统鼠标移动,可以做像qq一样的忙碌检测
qDebug() pt.x;
}
}
return false;
}
main.cpp
#include "mainwindow.h"
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
a.installNativeEventFilter(&w);
return a.exec();
}
qt捕获全局windows消息
标签:als public vat null patch xpl 全局 gen clu
原文地址:https://www.cnblogs.com/xiang--liu/p/12034608.html
评论