Fix crash on Dark mode under Windows 8

Fix #9911
This commit is contained in:
Don HO 2021-05-27 19:32:28 +02:00
parent 51207a4fe5
commit 5758b99b3e
1 changed files with 12 additions and 10 deletions

View File

@ -85,13 +85,13 @@ fnSetWindowCompositionAttribute _SetWindowCompositionAttribute = nullptr;
fnShouldAppsUseDarkMode _ShouldAppsUseDarkMode = nullptr; fnShouldAppsUseDarkMode _ShouldAppsUseDarkMode = nullptr;
fnAllowDarkModeForWindow _AllowDarkModeForWindow = nullptr; fnAllowDarkModeForWindow _AllowDarkModeForWindow = nullptr;
fnAllowDarkModeForApp _AllowDarkModeForApp = nullptr; fnAllowDarkModeForApp _AllowDarkModeForApp = nullptr;
fnFlushMenuThemes _FlushMenuThemes = nullptr; //fnFlushMenuThemes _FlushMenuThemes = nullptr;
fnRefreshImmersiveColorPolicyState _RefreshImmersiveColorPolicyState = nullptr; fnRefreshImmersiveColorPolicyState _RefreshImmersiveColorPolicyState = nullptr;
fnIsDarkModeAllowedForWindow _IsDarkModeAllowedForWindow = nullptr; fnIsDarkModeAllowedForWindow _IsDarkModeAllowedForWindow = nullptr;
fnGetIsImmersiveColorUsingHighContrast _GetIsImmersiveColorUsingHighContrast = nullptr; fnGetIsImmersiveColorUsingHighContrast _GetIsImmersiveColorUsingHighContrast = nullptr;
fnOpenNcThemeData _OpenNcThemeData = nullptr; fnOpenNcThemeData _OpenNcThemeData = nullptr;
// 1903 18362 // 1903 18362
fnShouldSystemUseDarkMode _ShouldSystemUseDarkMode = nullptr; //fnShouldSystemUseDarkMode _ShouldSystemUseDarkMode = nullptr;
fnSetPreferredAppMode _SetPreferredAppMode = nullptr; fnSetPreferredAppMode _SetPreferredAppMode = nullptr;
bool g_darkModeSupported = false; bool g_darkModeSupported = false;
@ -110,7 +110,7 @@ bool ShouldAppsUseDarkMode()
bool AllowDarkModeForWindow(HWND hWnd, bool allow) bool AllowDarkModeForWindow(HWND hWnd, bool allow)
{ {
if (g_darkModeSupported) if (g_darkModeSupported && _AllowDarkModeForWindow)
return _AllowDarkModeForWindow(hWnd, allow); return _AllowDarkModeForWindow(hWnd, allow);
return false; return false;
} }
@ -137,11 +137,12 @@ void SetTitleBarThemeColor(HWND hWnd, BOOL dark)
void RefreshTitleBarThemeColor(HWND hWnd) void RefreshTitleBarThemeColor(HWND hWnd)
{ {
BOOL dark = FALSE; BOOL dark = FALSE;
if (_IsDarkModeAllowedForWindow(hWnd) && if (_IsDarkModeAllowedForWindow && _ShouldAppsUseDarkMode)
_ShouldAppsUseDarkMode() &&
!IsHighContrast())
{ {
dark = TRUE; if (_IsDarkModeAllowedForWindow(hWnd) && _ShouldAppsUseDarkMode() && !IsHighContrast())
{
dark = TRUE;
}
} }
SetTitleBarThemeColor(hWnd, dark); SetTitleBarThemeColor(hWnd, dark);
@ -150,12 +151,13 @@ void RefreshTitleBarThemeColor(HWND hWnd)
bool IsColorSchemeChangeMessage(LPARAM lParam) bool IsColorSchemeChangeMessage(LPARAM lParam)
{ {
bool is = false; bool is = false;
if (lParam && (0 == lstrcmpi(reinterpret_cast<LPCWCH>(lParam), L"ImmersiveColorSet"))) if (lParam && (0 == lstrcmpi(reinterpret_cast<LPCWCH>(lParam), L"ImmersiveColorSet")) && _RefreshImmersiveColorPolicyState)
{ {
_RefreshImmersiveColorPolicyState(); _RefreshImmersiveColorPolicyState();
is = true; is = true;
} }
_GetIsImmersiveColorUsingHighContrast(IHCM_REFRESH); if (_GetIsImmersiveColorUsingHighContrast)
_GetIsImmersiveColorUsingHighContrast(IHCM_REFRESH);
return is; return is;
} }
@ -209,7 +211,7 @@ void FixDarkScrollBar()
if (addr) if (addr)
{ {
DWORD oldProtect; 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 { auto MyOpenThemeData = [](HWND hWnd, LPCWSTR classList) -> HTHEME {
if (wcscmp(classList, L"ScrollBar") == 0) if (wcscmp(classList, L"ScrollBar") == 0)