From 677e7a737897e8c2a60564085821545810369e02 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周一, 11 12月 2023 22:43:14 +0800 Subject: [PATCH] Widgets: Add window state handler --- src/core/contexts/win32windowcontext.cpp | 53 ++++++++++++++++++++++++++--------------------------- 1 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp index 56513a9..ea68c0d 100644 --- a/src/core/contexts/win32windowcontext.cpp +++ b/src/core/contexts/win32windowcontext.cpp @@ -749,33 +749,13 @@ return ::DefWindowProcW(hWnd, message, wParam, lParam); } - switch (message) { - case WM_NCCALCSIZE: { - // Since Qt does the necessary processing of the WM_NCCALCSIZE message, we need to - // forward it right away and process it in our native event filter. - WindowsNativeEventFilter::lastMessageContext = ctx; - LRESULT result = ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam); - WindowsNativeEventFilter::lastMessageContext = nullptr; - return result; - } - - case WM_WINDOWPOSCHANGING: { - // When toggling the "Show theme color in title bar and window border" setting in - // Windows Settings, or calling `DrawMenuBar()`, Windows sends a message of - // WM_WINDOWPOSCHANGING with flags 0x37. If we do not process this message, - // the client area as a whole will shift to the left, which looks very abnormal if - // we don't repaint it. This exception disappears if we add SWP_NOCOPYBITS flag. - // But I don't know what caused the problem, or why this would solve it. - const auto windowPos = reinterpret_cast<LPWINDOWPOS>(lParam); - if (windowPos->flags == - (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED)) { - windowPos->flags |= SWP_NOCOPYBITS; - } - return ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam); - } - - default: - break; + // Since Qt does the necessary processing of the WM_NCCALCSIZE message, we need to + // forward it right away and process it in our native event filter. + if (message == WM_NCCALCSIZE) { + WindowsNativeEventFilter::lastMessageContext = ctx; + LRESULT result = ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam); + WindowsNativeEventFilter::lastMessageContext = nullptr; + return result; } // Try hooked procedure and save result @@ -1250,6 +1230,7 @@ } break; } + case WM_NCHITTEST: { // 鍘熺敓Win32绐楀彛鍙湁椤惰竟鏄湪绐楀彛鍐呴儴resize鐨勶紝鍏朵綑涓夎竟閮芥槸鍦ㄧ獥鍙� // 澶栭儴杩涜resize鐨勶紝鍏跺師鐞嗘槸锛學S_THICKFRAME杩欎釜绐楀彛鏍峰紡浼氬湪绐� @@ -1538,9 +1519,27 @@ return true; } } + + case WM_WINDOWPOSCHANGING: { + // ### FIXME: How does this problem happen and why is it solved? + // When toggling the "Show theme color in title bar and window border" setting in + // Windows Settings, or calling `DrawMenuBar()`, Windows sends a message of + // WM_WINDOWPOSCHANGING with flags 0x37. If we do not process this message, + // the client area as a whole will shift to the left, which looks very abnormal if + // we don't repaint it. This exception disappears if we add SWP_NOCOPYBITS flag. + // But I don't know what caused the problem, or why this would solve it. + const auto windowPos = reinterpret_cast<LPWINDOWPOS>(lParam); + if (windowPos->flags == + (SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED)) { + windowPos->flags |= SWP_NOCOPYBITS; + } + break; + } + default: break; } + if (!isWin10OrGreater()) { switch (message) { case WM_NCUAHDRAWCAPTION: -- Gitblit v1.9.1