0

I am trying to make application that has color theme of users windows theme (Form Background, text color etc..)

Is it possible to get #color that the user has selected in their Win 8.1/10?

I am talking about this specific setting:

enter image description here

AleRemote225
  • 93
  • 1
  • 7
  • 1
    They don't want you to know. Most obvious from [this correct code](https://code.msdn.microsoft.com/windowsdesktop/How-to-get-Accent-brush-6652403f). – Hans Passant Jun 12 '16 at 13:42
  • Hans is right, it's still undocumented. I cannot understand why they wouldn't want you to know. Microsoft seems to be moving more and more *away* from a consistent UI experience these days, something that has long been their biggest advantage. Oh well, now it's up to us independent app developers to do something about it and keep our apps user-friendly. Thank you for paying attention to these things and trying to do this. – Cody Gray - on strike Jun 12 '16 at 17:03
  • "they don't want you to know" == "it is going to change". This is an eye-candy color. Microsoft has to keep it looking good to keep up with the Joneses, the next version is going to look very different. And won't use this color. – Hans Passant Jun 19 '16 at 07:56
  • 1
    @HansPassant it's 2020 and that feature hasn't changed. AFAIK, there is now a documented way to get the accent color using the Microsoft.Windows.SDK.Contracts package. See for example this [answer](https://stackoverflow.com/a/58528170/8781554). – Xam Jul 14 '20 at 23:03
  • You can at least get the accent color using `SystemParameters.WindowGlassColor`. – mav Jan 23 '23 at 08:10

1 Answers1

4

This is an example i have created, also based on the link that Hans Passant posted above. Another similar approach can be found on GitHub see AccentColorService

public class ThemeInfo
{
    [DllImport("uxtheme.dll", EntryPoint = "#95")]
    public static extern uint GetImmersiveColorFromColorSetEx(uint dwImmersiveColorSet, uint dwImmersiveColorType, bool bIgnoreHighContrast, uint dwHighContrastCacheMode);
    [DllImport("uxtheme.dll", EntryPoint = "#96")]
    public static extern uint GetImmersiveColorTypeFromName(IntPtr pName);
    [DllImport("uxtheme.dll", EntryPoint = "#98")]
    public static extern int GetImmersiveUserColorSetPreference(bool bForceCheckRegistry, bool bSkipCheckOnFail);

    public Color GetThemeColor()
    {
        var colorSetEx = GetImmersiveColorFromColorSetEx(
            (uint)GetImmersiveUserColorSetPreference(false, false),
            GetImmersiveColorTypeFromName(Marshal.StringToHGlobalUni("ImmersiveStartSelectionBackground")),
            false, 0);

        var colour = Color.FromArgb((byte)((0xFF000000 & colorSetEx) >> 24), (byte)(0x000000FF & colorSetEx),
            (byte)((0x0000FF00 & colorSetEx) >> 8), (byte)((0x00FF0000 & colorSetEx) >> 16));

        return colour;
    }
}
driconmax
  • 956
  • 1
  • 18
  • 32
Dave Wijnen
  • 71
  • 2
  • 7