From e169c219a0420dd9a9ef90757cf64c10e1a20075 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao Date: Sun, 8 Oct 2023 10:54:29 +0800 Subject: [PATCH] win: minor tweaks --- src/core/framelesshelper_win.cpp | 38 +++++++++++++++++++++++++ src/core/framelesshelpercore_global.cpp | 2 +- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 663b6e29..ec87d0bc 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -1201,6 +1201,44 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me } } } break; + case WM_STYLECHANGED: { + // The window style has been changed. + if (wParam & GWL_STYLE) { + // We need a little delay here because Qt will always change the window style + // first and then change the window geometry, however we need to check the window + // geometry to see if we need to adjust the window style or not, so we need to + // wait until the window geometry has been changed. + QTimer::singleShot(0, qWindow, [windowId, hWnd](){ + // There's nothing to do when the window is fullscreened. + if (Utils::isFullScreen(windowId)) { + return; + } + // Check if the window style is "broken" when we are not fullscreened. + ::SetLastError(ERROR_SUCCESS); + auto dwStyle = static_cast(::GetWindowLongPtrW(hWnd, GWL_STYLE)); + if (dwStyle == 0) { + WARNING << Utils::getSystemErrorMessage(kGetWindowLongPtrW); + return; + } + // Avoid infinite recursions by not touching the window style if it's + // appropriate. + const bool hasPopup = (dwStyle & WS_POPUP); + const bool thickFrameMissing = !(dwStyle & WS_THICKFRAME); + if (!(hasPopup || thickFrameMissing)) { + return; + } + dwStyle &= ~WS_POPUP; + dwStyle |= WS_THICKFRAME; + ::SetLastError(ERROR_SUCCESS); + if (::SetWindowLongPtrW(hWnd, GWL_STYLE, LONG_PTR(dwStyle)) == 0) { + WARNING << Utils::getSystemErrorMessage(kSetWindowLongPtrW); + } + }); + } + // The extended window style has been changed. + if (wParam & GWL_EXSTYLE) { + } + } break; default: break; } diff --git a/src/core/framelesshelpercore_global.cpp b/src/core/framelesshelpercore_global.cpp index 7b50ba56..51f539c9 100644 --- a/src/core/framelesshelpercore_global.cpp +++ b/src/core/framelesshelpercore_global.cpp @@ -268,7 +268,7 @@ void FramelessHelperPrintLogo() QString message = {}; QTextStream stream(&message, QIODevice::WriteOnly); stream << "FramelessHelper (" << (ver.build.is_static ? "static" : "shared") - << ", " << (ver.build.is_debug ? "debug" : "release") + << ", " << (ver.build.is_debug ? "debug" : "release") << ", " << ver.build.architecture << ") version " << ver.version.str << ", author wangwenx190 (Yuhang Zhao, 2546789017@qq.com)." << " Built by " << ver.compiler.name << ver.compiler.version