Mercurial > dwindows
changeset 1966:d510e9bb61c2
Win: First attempt at enabling Dark Mode support, mixed results... some changes.
However just produces an awkward mess of light and dark mode widgets.
Setting support to FALSE by default.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Tue, 30 Jul 2019 07:53:57 +0000 |
parents | 6315f668f5f6 |
children | 22c96cd42eb8 |
files | win/dw.c |
diffstat | 1 files changed, 26 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/win/dw.c Sun Jul 28 23:41:53 2019 +0000 +++ b/win/dw.c Tue Jul 30 07:53:57 2019 +0000 @@ -671,27 +671,30 @@ } #endif -int _DW_DARK_MODE_ALLOWED = TRUE; +int _DW_DARK_MODE_ALLOWED = FALSE; /* Call this on a window to apply the style */ -void _set_window_theme(HWND window) -{ - static int initialized = FALSE; - BOOL (WINAPI * AllowDarkModeForWindow)(HWND a_HWND, BOOL a_Allow) = NULL; - - if(initialized == FALSE && dwVersion) - { - /* Dark mode is introduced in Windows 10 build 1809 */ - if(LOBYTE(LOWORD(dwVersion)) == 10 && HIWORD(dwVersion) >= 1809) - AllowDarkModeForWindow = (BOOL (WINAPI *)(HWND, BOOL))GetProcAddress(huxtheme, MAKEINTRESOURCEA(133)); - initialized = TRUE; - } - if(AllowDarkModeForWindow) - { - AllowDarkModeForWindow(window, _DW_DARK_MODE_ALLOWED); - if(_DW_DARK_MODE_ALLOWED && _SetWindowTheme) - _SetWindowTheme(window, L"Explorer", NULL); - } +BOOL CALLBACK _set_child_window_theme(HWND window, LPARAM lParam) +{ + static int initialized = FALSE; + static BOOL (WINAPI * AllowDarkModeForWindow)(HWND a_HWND, BOOL a_Allow) = NULL; + + if(initialized == FALSE && dwVersion) + { + /* Dark mode is introduced in Windows 10 (1809) build 17763 */ + if(LOBYTE(LOWORD(dwVersion)) >= 10 && HIWORD(dwVersion) >= 17763) + AllowDarkModeForWindow = (BOOL (WINAPI *)(HWND, BOOL))GetProcAddress(huxtheme, MAKEINTRESOURCEA(133)); + initialized = TRUE; + } + if(AllowDarkModeForWindow) + { + AllowDarkModeForWindow(window, _DW_DARK_MODE_ALLOWED); + if(_DW_DARK_MODE_ALLOWED && _SetWindowTheme) + { + _SetWindowTheme(window, L"DarkMode_Explorer", NULL); + } + } + return TRUE; } /* This function adds a signal handler callback into the linked list. @@ -4269,6 +4272,10 @@ int rc; RECT rect; + /* Try to enable dark mode support if our OS supports it */ + _set_child_window_theme(handle, 0); + EnumChildWindows(handle, _set_child_window_theme, 0); + GetClientRect(handle, &rect); /* If the client area is 0x0 then call the autosize routine */