win32: minor improvement

Signed-off-by: Yuhang Zhao <2546789017@qq.com>
This commit is contained in:
Yuhang Zhao 2022-07-30 17:26:27 +08:00
parent 775b1a2aab
commit f4f56498c2
3 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -504,6 +504,7 @@ void FramelessHelperWin::addWindow(const SystemParameters &params)
}
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);

View File

@ -38,6 +38,7 @@
#include "framelesshelper_windows.h"
#include "framelessconfig_p.h"
#include "sysapiloader_p.h"
#include <uxtheme.h>
#include <d2d1.h>
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<HWND>(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