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

Viewed 2008

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

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.

Related