Some questions about nativeEnentFilter using window messages
-
Hello,I was working on a borderless window project recently, and there were some problems when using nativeEventFilter. When I received the message from windows in the nativeEventFilter function, the returned WM_NCCALCSIZE message was filtered, and then the border of my main window disappeared automatically. , I can’t find out what is causing the problem. Please help analyze why this is the case. I didn’t set FramelessWindowHint in my original window.
main.cpp
int main(int argc, char *argv[]) { QApplication a(argc, argv); FFTMainWindow w; w.show(); NativeEventHelper helper(&w); // helper = new NativeEventHelper(w); a.installNativeEventFilter(&helper); return a.exec(); }
NativeEventHelper.cpp
bool NativeEventHelper::nativeEventFilter(const QByteArray &eventType, void *message, long *result) { #ifdef Q_OS_WIN if (eventType != "windows_generic_MSG") return false; MSG* msg = static_cast<MSG*>(message); QWidget* widget = QWidget::find(reinterpret_cast<WId>(msg->hwnd)); // qDebug()<<"----widget----"<<widget; if (!widget) return false; switch (msg->message) { case WM_NCCALCSIZE: { qDebug()<<"----WM_NCCALCSIZE----"; *result = 0; return true; } default: break; #endif return QWidget::nativeEvent(eventType, message, result); }
-
@Ming_tft said in Some questions about nativeEnentFilter using window messages:
case WM_NCCALCSIZE: { qDebug()<<"----WM_NCCALCSIZE----"; *result = 0; return true;
the returned WM_NCCALCSIZE message was filtered, and then the border of my main window disappeared automatically. , I can’t find out what is causing the problem.
You tell the caller that WM_NCCALCSIZE should be filtered.
-
@Ming_tft said in Some questions about nativeEnentFilter using window messages:
case WM_NCCALCSIZE: { qDebug()<<"----WM_NCCALCSIZE----"; *result = 0; return true;
the returned WM_NCCALCSIZE message was filtered, and then the border of my main window disappeared automatically. , I can’t find out what is causing the problem.
You tell the caller that WM_NCCALCSIZE should be filtered.
@Christian-Ehrlicher Thank you for your reply, it is helpful to me. In addition, I would like to ask another question. If I want to filter this way, I only want the main window to receive messages, but I don't want the child window control QWidget to receive messages. Can this be achieved? Or can it only be achieved by overloading the nativeEvent function on QMainWindow? Hope your reply