Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows 10: GetSysColor() does not get dark ui color theme

Tags:

colors

winapi

On Windows 10, the "dark theme" is now available.

In Tk, GetSysColor() is used to get the windows system colors, and WM_SYSCOLORCHANGE is used to track color changes.

When a high contrast theme is selected, Tk picks up the color changes.

When the dark-ui is selected, Tk does not see the color changes, and restarting the program does not pick up the color changes.

Is there something special that needs to be done to get these colors?

Edit:

These are the relevant files in Tk:

Manifest: http://core.tcl.tk/tk/artifact/52574f6bb5c1c0d6

Monitoring code: http://core.tcl.tk/tk/artifact/4629f358581eb7aa

Initialization/VS API code: http://core.tcl.tk/tk/artifact/ab91ac197b786344

like image 900
Brad Lanam Avatar asked Aug 30 '18 16:08

Brad Lanam


People also ask

Why does my Windows 10 not have dark mode?

To enable dark mode, navigate to Settings > Personalization > Colors, then open the drop-down menu for "Choose your color" and pick Dark. Dark (and Light) mode change the look of the Windows Start menu and built-in apps.

How do I change to dark mode in Visual Studio?

On the menu bar, select Tools > Options. In the options list, select Environment > General. In the Color theme list, choose between the default Dark theme, the Blue theme, the Blue (Extra Contrast) theme, and the Light theme. Or, choose the Use system setting option to select the theme that Windows uses.


1 Answers

Update: Microsoft improves dark theme handling in newer versions of Windows 10, so in some point this answer will be outdated.


Generally Dark/Light-Theme switch is intended for "modern" UWP apps only. You can verify that Calculator, Calendar and Contacts switch colors but classic apps Explorer, Notepad and Paint don't.

I'm not sure if you want to port Tk to UWP, because you don't seem to do any steps in this direction. In the case of classic apps dark mode is problematic because basic Windows controls (buttons, labels, edit fields) do not support it.

If you really want to change something in response to the Light/Dark setting switch in the classic application, get DWORD value from HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme

bool IsDarkThemeActive()
{
    DWORD   type;
    DWORD   value;
    DWORD   count = 4;
    LSTATUS st = RegGetValue(
        HKEY_CURRENT_USER,
        TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"),
        TEXT("AppsUseLightTheme"),
        RRF_RT_REG_DWORD,
        &type,
        &value,
        &count );
    if ( st == ERROR_SUCCESS && type == REG_DWORD )
        return value == 0;
    return false;
}

When the Light/Dark setting is changed top level windows get WM_SETTINGCHANGE message.

like image 138
Daniel Sęk Avatar answered Nov 26 '22 06:11

Daniel Sęk