From cbf34ea0ec94e565890feb4b74a02726605766d8 Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Mon, 4 Jul 2022 13:03:23 +0800 Subject: [PATCH] win32: try to fix bug Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- examples/example.manifest | 4 +- .../Core/framelesshelper_windows.h | 63 ++++++++++++++++--- src/core/utils_win.cpp | 7 ++- src/quick/framelessquickhelper.cpp | 1 + src/widgets/framelesswidgetshelper.cpp | 1 + 5 files changed, 66 insertions(+), 10 deletions(-) diff --git a/examples/example.manifest b/examples/example.manifest index 419472c..7faca64 100644 --- a/examples/example.manifest +++ b/examples/example.manifest @@ -54,6 +54,8 @@ + + @@ -62,7 +64,7 @@ - + diff --git a/include/FramelessHelper/Core/framelesshelper_windows.h b/include/FramelessHelper/Core/framelesshelper_windows.h index 5198d88..e377b6c 100644 --- a/include/FramelessHelper/Core/framelesshelper_windows.h +++ b/include/FramelessHelper/Core/framelesshelper_windows.h @@ -135,6 +135,24 @@ # define TIMERR_NOERROR (0) #endif +#ifndef WS_EX_NOREDIRECTIONBITMAP +# define WS_EX_NOREDIRECTIONBITMAP (0x00200000L) +#endif + +#ifndef USER_DEFAULT_SCREEN_DPI +# define USER_DEFAULT_SCREEN_DPI (96) +#endif + +#ifndef _DPI_AWARENESS_CONTEXTS_ +# define _DPI_AWARENESS_CONTEXTS_ + DECLARE_HANDLE(DPI_AWARENESS_CONTEXT); +# define DPI_AWARENESS_CONTEXT_UNAWARE ((DPI_AWARENESS_CONTEXT)-1) +# define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ((DPI_AWARENESS_CONTEXT)-2) +# define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ((DPI_AWARENESS_CONTEXT)-3) +# define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ((DPI_AWARENESS_CONTEXT)-4) +# define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED ((DPI_AWARENESS_CONTEXT)-5) +#endif + using MMRESULT = UINT; using TIMECAPS = struct TIMECAPS @@ -162,6 +180,17 @@ using MONITOR_DPI_TYPE = enum MONITOR_DPI_TYPE MDT_DEFAULT = MDT_EFFECTIVE_DPI }; +using _DWMWINDOWATTRIBUTE = enum _DWMWINDOWATTRIBUTE +{ + _DWMWA_USE_HOSTBACKDROPBRUSH = 17, + _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19, // Undocumented + _DWMWA_USE_IMMERSIVE_DARK_MODE = 20, + _DWMWA_WINDOW_CORNER_PREFERENCE = 33, + _DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37, + _DWMWA_SYSTEMBACKDROP_TYPE = 38, + _DWMWA_MICA_EFFECT = 1029 // Undocumented +}; + using _DWM_WINDOW_CORNER_PREFERENCE = enum _DWM_WINDOW_CORNER_PREFERENCE { _DWMWCP_DEFAULT = 0, // Let the system decide whether or not to round window corners @@ -278,6 +307,32 @@ GetDpiForMonitor( _Out_ UINT *dpiY ); +WINUSERAPI int WINAPI +GetSystemMetricsForDpi( + _In_ int nIndex, + _In_ UINT dpi +); + +WINUSERAPI UINT WINAPI +GetDpiForWindow( + _In_ HWND hwnd +); + +WINUSERAPI UINT WINAPI +GetSystemDpiForProcess( + _In_ HANDLE hProcess +); + +WINUSERAPI BOOL WINAPI +SetProcessDpiAwarenessContext( + _In_ DPI_AWARENESS_CONTEXT value +); + +WINUSERAPI BOOL WINAPI +SetProcessDPIAware( + VOID +); + [[maybe_unused]] static constexpr const int kAutoHideTaskBarThickness = 2; // The thickness of an auto-hide taskbar in pixels. [[maybe_unused]] static constexpr const wchar_t kDwmRegistryKey[] = LR"(Software\Microsoft\Windows\DWM)"; @@ -286,11 +341,3 @@ GetDpiForMonitor( [[maybe_unused]] static constexpr const wchar_t kDwmColorKeyName[] = L"ColorPrevalence"; [[maybe_unused]] static constexpr const wchar_t kSystemDarkThemeResourceName[] = L"DarkMode_Explorer"; [[maybe_unused]] static constexpr const wchar_t kSystemLightThemeResourceName[] = L"Explorer"; - -[[maybe_unused]] static constexpr const DWORD _DWMWA_USE_HOSTBACKDROPBRUSH = 17; -[[maybe_unused]] static constexpr const DWORD _DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19; -[[maybe_unused]] static constexpr const DWORD _DWMWA_USE_IMMERSIVE_DARK_MODE = 20; -[[maybe_unused]] static constexpr const DWORD _DWMWA_WINDOW_CORNER_PREFERENCE = 33; -[[maybe_unused]] static constexpr const DWORD _DWMWA_VISIBLE_FRAME_BORDER_THICKNESS = 37; -[[maybe_unused]] static constexpr const DWORD _DWMWA_SYSTEMBACKDROP_TYPE = 38; -[[maybe_unused]] static constexpr const DWORD _DWMWA_MICA_EFFECT = 1029; diff --git a/src/core/utils_win.cpp b/src/core/utils_win.cpp index 8cc44cc..b911e6a 100644 --- a/src/core/utils_win.cpp +++ b/src/core/utils_win.cpp @@ -1495,10 +1495,15 @@ bool Utils::setBlurBehindWindowEnabled(const WId windowId, const BlurMode mode, } if (isWin11OrGreater) { const BOOL enable = FALSE; - const HRESULT hr = pDwmSetWindowAttribute(hwnd, _DWMWA_MICA_EFFECT, &enable, sizeof(enable)); + HRESULT hr = pDwmSetWindowAttribute(hwnd, _DWMWA_MICA_EFFECT, &enable, sizeof(enable)); if (FAILED(hr)) { qWarning() << __getSystemErrorMessage(kDwmSetWindowAttribute, hr); } + const MARGINS margins = {0, 0, 0, 0}; + hr = pDwmExtendFrameIntoClientArea(hwnd, &margins); + if (FAILED(hr)) { + qWarning() << __getSystemErrorMessage(kDwmExtendFrameIntoClientArea, hr); + } } ACCENT_POLICY policy; SecureZeroMemory(&policy, sizeof(policy)); diff --git a/src/quick/framelessquickhelper.cpp b/src/quick/framelessquickhelper.cpp index 210ae14..1dfb770 100644 --- a/src/quick/framelessquickhelper.cpp +++ b/src/quick/framelessquickhelper.cpp @@ -26,6 +26,7 @@ #include "framelessquickhelper_p.h" #include #include +#include #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) # include // For QWINDOWSIZE_MAX #else diff --git a/src/widgets/framelesswidgetshelper.cpp b/src/widgets/framelesswidgetshelper.cpp index a299d98..78782c5 100644 --- a/src/widgets/framelesswidgetshelper.cpp +++ b/src/widgets/framelesswidgetshelper.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include