From f4f56498c28d4c1d8afd498e4e61abe8e43a73e1 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sat, 30 Jul 2022 17:26:27 +0800 Subject: [PATCH] win32: minor improvement Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- include/FramelessHelper/Core/utils.h | 2 ++ src/core/framelesshelper_win.cpp | 1 + src/core/utils_win.cpp | 23 +++++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/FramelessHelper/Core/utils.h b/include/FramelessHelper/Core/utils.h index aaa7a35..02daeaf 100644 --- a/include/FramelessHelper/Core/utils.h +++ b/include/FramelessHelper/Core/utils.h @@ -118,6 +118,8 @@ FRAMELESSHELPER_CORE_API void updateGlobalWin32ControlsTheme(const WId windowId, [[nodiscard]] FRAMELESSHELPER_CORE_API bool shouldAppsUseDarkMode_windows(); FRAMELESSHELPER_CORE_API void forceSquareCornersForWindow(const WId windowId, const bool force); [[nodiscard]] FRAMELESSHELPER_CORE_API QColor getDwmAccentColor(); +FRAMELESSHELPER_CORE_API void disableOriginalTitleBarFunctionalities + (const WId windowId, const bool disable = true); #endif // Q_OS_WINDOWS #ifdef Q_OS_LINUX diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index ea9904d..556931d 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -504,6 +504,7 @@ void FramelessHelperWin::addWindow(const SystemParameters ¶ms) } g_win32Helper()->mutex.unlock(); Utils::fixupQtInternals(windowId); + Utils::disableOriginalTitleBarFunctionalities(windowId); Utils::updateInternalWindowFrameMargins(params.getWindowHandle(), true); Utils::updateWindowFrameMargins(windowId, false); static const bool isWin10RS1OrGreater = Utils::isWindowsVersionOrGreater(WindowsVersion::_10_1607); diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 2689b55..3c348ff 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -38,6 +38,7 @@ #include "framelesshelper_windows.h" #include "framelessconfig_p.h" #include "sysapiloader_p.h" +#include #include Q_DECLARE_METATYPE(QMargins) @@ -134,6 +135,7 @@ FRAMELESSHELPER_STRING_CONSTANT(WallpaperStyle) FRAMELESSHELPER_STRING_CONSTANT(TileWallpaper) FRAMELESSHELPER_STRING_CONSTANT(UnregisterClassW) FRAMELESSHELPER_STRING_CONSTANT(DestroyWindow) +FRAMELESSHELPER_STRING_CONSTANT(SetWindowThemeAttribute) struct Win32UtilsHelperData { @@ -1841,4 +1843,25 @@ bool Utils::isBlurBehindWindowSupported() return result; } +void Utils::disableOriginalTitleBarFunctionalities(const WId windowId, const bool disable) +{ + Q_ASSERT(windowId); + if (!windowId) { + return; + } + if (!API_THEME_AVAILABLE(SetWindowThemeAttribute)) { + return; + } + const auto hwnd = reinterpret_cast(windowId); + WTA_OPTIONS options; + SecureZeroMemory(&options, sizeof(options)); + options.dwFlags = options.dwMask = (disable ? + (WTNCA_NODRAWCAPTION | WTNCA_NODRAWICON | WTNCA_NOSYSMENU) : 0); + const HRESULT hr = API_CALL_FUNCTION(SetWindowThemeAttribute, + hwnd, WTA_NONCLIENT, &options, sizeof(options)); + if (FAILED(hr)) { + WARNING << __getSystemErrorMessage(kSetWindowThemeAttribute, hr); + } +} + FRAMELESSHELPER_END_NAMESPACE