From 5758b99b3edd4db7ba8a01ca08cfd5e1cc6af3e2 Mon Sep 17 00:00:00 2001 From: Don HO Date: Thu, 27 May 2021 19:32:28 +0200 Subject: [PATCH] Fix crash on Dark mode under Windows 8 Fix #9911 --- PowerEditor/src/DarkMode/DarkMode.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/PowerEditor/src/DarkMode/DarkMode.cpp b/PowerEditor/src/DarkMode/DarkMode.cpp index 91e379064..3a8f5b366 100644 --- a/PowerEditor/src/DarkMode/DarkMode.cpp +++ b/PowerEditor/src/DarkMode/DarkMode.cpp @@ -85,13 +85,13 @@ fnSetWindowCompositionAttribute _SetWindowCompositionAttribute = nullptr; fnShouldAppsUseDarkMode _ShouldAppsUseDarkMode = nullptr; fnAllowDarkModeForWindow _AllowDarkModeForWindow = nullptr; fnAllowDarkModeForApp _AllowDarkModeForApp = nullptr; -fnFlushMenuThemes _FlushMenuThemes = nullptr; +//fnFlushMenuThemes _FlushMenuThemes = nullptr; fnRefreshImmersiveColorPolicyState _RefreshImmersiveColorPolicyState = nullptr; fnIsDarkModeAllowedForWindow _IsDarkModeAllowedForWindow = nullptr; fnGetIsImmersiveColorUsingHighContrast _GetIsImmersiveColorUsingHighContrast = nullptr; fnOpenNcThemeData _OpenNcThemeData = nullptr; // 1903 18362 -fnShouldSystemUseDarkMode _ShouldSystemUseDarkMode = nullptr; +//fnShouldSystemUseDarkMode _ShouldSystemUseDarkMode = nullptr; fnSetPreferredAppMode _SetPreferredAppMode = nullptr; bool g_darkModeSupported = false; @@ -110,7 +110,7 @@ bool ShouldAppsUseDarkMode() bool AllowDarkModeForWindow(HWND hWnd, bool allow) { - if (g_darkModeSupported) + if (g_darkModeSupported && _AllowDarkModeForWindow) return _AllowDarkModeForWindow(hWnd, allow); return false; } @@ -137,11 +137,12 @@ void SetTitleBarThemeColor(HWND hWnd, BOOL dark) void RefreshTitleBarThemeColor(HWND hWnd) { BOOL dark = FALSE; - if (_IsDarkModeAllowedForWindow(hWnd) && - _ShouldAppsUseDarkMode() && - !IsHighContrast()) + if (_IsDarkModeAllowedForWindow && _ShouldAppsUseDarkMode) { - dark = TRUE; + if (_IsDarkModeAllowedForWindow(hWnd) && _ShouldAppsUseDarkMode() && !IsHighContrast()) + { + dark = TRUE; + } } SetTitleBarThemeColor(hWnd, dark); @@ -150,12 +151,13 @@ void RefreshTitleBarThemeColor(HWND hWnd) bool IsColorSchemeChangeMessage(LPARAM lParam) { bool is = false; - if (lParam && (0 == lstrcmpi(reinterpret_cast(lParam), L"ImmersiveColorSet"))) + if (lParam && (0 == lstrcmpi(reinterpret_cast(lParam), L"ImmersiveColorSet")) && _RefreshImmersiveColorPolicyState) { _RefreshImmersiveColorPolicyState(); is = true; } - _GetIsImmersiveColorUsingHighContrast(IHCM_REFRESH); + if (_GetIsImmersiveColorUsingHighContrast) + _GetIsImmersiveColorUsingHighContrast(IHCM_REFRESH); return is; } @@ -209,7 +211,7 @@ void FixDarkScrollBar() if (addr) { DWORD oldProtect; - if (VirtualProtect(addr, sizeof(IMAGE_THUNK_DATA), PAGE_READWRITE, &oldProtect)) + if (VirtualProtect(addr, sizeof(IMAGE_THUNK_DATA), PAGE_READWRITE, &oldProtect) && _OpenNcThemeData) { auto MyOpenThemeData = [](HWND hWnd, LPCWSTR classList) -> HTHEME { if (wcscmp(classList, L"ScrollBar") == 0)