On 2022-08-02 00:07, Laszlo Papp wrote:
#include <QAbstractNativeEventFilter>
#include <QApplication>
#include <iostream>
class MyMSGEventFilter : public QAbstractNativeEventFilter
{
public:
bool nativeEventFilter(const QByteArray &eventType,
[[maybe_unused]] void *message, long *) override
{
std::cout << eventType.toStdString() << std::endl;
#ifdef Q_OS_WIN
if (eventType == "windows_generic_MSG") {
MSG *msg = static_cast<MSG *>(message);
} else if (eventType == "windows_dispatcher_MSG") {
MSG *msg = static_cast<MSG *>(message);
}
#endif
return false;
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyMSGEventFilter filterObject;
app.installNativeEventFilter(&filterObject);
return app.exec();
}
Hi, it works fine on Windows, but without a (hidden) window on the
desktop you're doomed to receiving *very few* message. I.e. no HWND
(that's why for example the DDE server creates a hidden window on the
desktop). So easiest workaround is to add say a QWidget window:
...
QApplication app(argc, argv);
MyMSGEventFilter filterObject;
app.installNativeEventFilter(&filterObject);
MainWindow w;
w.show(); // you can hide it now
return app.exec();
...
BTW, I couldn't get it to compile on MSVC 2019 Qt 6.3.1
("MyMsgEventFilter: cannot instantiate abstract class") but on MSVC 2019
5.15.2 it works fine.
_______________________________________________
Development mailing list
Development@qt-project.org
https://lists.qt-project.org/listinfo/development