From ae92a0062869c891d97ce09e90603859788d20b5 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 18 Oct 2020 13:23:59 +0800 Subject: [PATCH] Guard against the event. Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/Win32Demo/widget.cpp | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/examples/Win32Demo/widget.cpp b/examples/Win32Demo/widget.cpp index 1d3d491..d3b5859 100644 --- a/examples/Win32Demo/widget.cpp +++ b/examples/Win32Demo/widget.cpp @@ -187,25 +187,27 @@ bool Widget::nativeEvent(const QByteArray &eventType, void *message, long *resul Q_ASSERT(eventType == "windows_generic_MSG"); Q_ASSERT(message); Q_ASSERT(result); - const auto msg = static_cast(message); - const auto getCursorPosition = [](const LPARAM lParam) -> QPoint { - return {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; - }; - switch (msg->message) { - case WM_NCRBUTTONUP: { - const QPoint pos = getCursorPosition(msg->lParam); - qDebug() << "WM_NCRBUTTONUP -->" << pos; - if (WinNativeEventFilter::displaySystemMenu(msg->hwnd, false, pos.x(), pos.y())) { - *result = 0; - return true; + if (ui->customizeTitleBarCB->isChecked()) { + const auto msg = static_cast(message); + const auto getCursorPosition = [](const LPARAM lParam) -> QPoint { + return {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)}; + }; + switch (msg->message) { + case WM_NCRBUTTONUP: { + const QPoint pos = getCursorPosition(msg->lParam); + qDebug() << "WM_NCRBUTTONUP -->" << pos; + if (WinNativeEventFilter::displaySystemMenu(msg->hwnd, false, pos.x(), pos.y())) { + *result = 0; + return true; + } + break; + } + case WM_RBUTTONUP: + qDebug() << "WM_RBUTTONUP -->" << getCursorPosition(msg->lParam); + break; + default: + break; } - break; - } - case WM_RBUTTONUP: - qDebug() << "WM_RBUTTONUP -->" << getCursorPosition(msg->lParam); - break; - default: - break; } return QWidget::nativeEvent(eventType, message, result); }