Search code examples
pythonwindowswinapicolorsregistry

Applying changes in HKCU\Control Panel\Colors immediately


I've been developing a color customization program recently and found how desk.cpl used to apply the HKCU\Control Panel\Colors changes immediately. How can I do this myself (in any langauge)? I don't want to use Windows API SetSysColors function because I'm primary coding this program in Python. Any way I can do this?

Remarks

  • I found that desk.cpl actually changes the registry (but I'm not sure how)
  • Winapi SetSysColors function emits a WM_SYSCOLORCHANGE message.

I have tried

  • Emitting a WM_SYSCOLORCHANGE to all components using BroadcastSystemMessage
  • Analyzing desk.cpl behavior as much as possible to find all that is does
  • Restarting explorer.exe

Solution

  • SetSysColors is the only way, it calls into the kernel.

    According to this mailing list post, the ctypes code looks like this:

    from ctypes.wintypes import windll, c_int, byref, RGB
    COLOR_BACKGROUND = 1 # from winuser.h or win32con
    SetSysColors = windll.user32.SetSysColors
    which_color = RGB(255,0,0) # red
    SetSysColors(1, byref(c_int(COLOR_BACKGROUND)), byref(c_int(which_color)))