Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

GetUserColorPreference (uxtheme)
 
.
Summary
GetUserColorPreference will get the current theme Accent color and the Start menu color through the IMMERSIVE_COLOR_PREFERENCE structure. Its counterpart is SetUserColorPreference

C# Signature:

    [DllImport("uxtheme.dll", EntryPoint = "#120")]
    static extern IntPtr GetUserColorPreference(ref IMMERSIVE_COLOR_PREFERENCE pcpPreference, bool fForceReload);

VB Signature:

Declare Function GetUserColorPreference Lib "uxtheme.dll" (TODO) As TODO

User-Defined Types:

    private struct IMMERSIVE_COLOR_PREFERENCE
    {
        public uint dwColorSetIndex;
        public uint crStartColor;
        public uint crAccentColor;
    }

Notes:

None.

Tips & Tricks:

To convert the uint color to the managed Color class and vice versa:

    private static uint ToUint(Color c)
    {
        return (uint)((c.B << 16) | (c.G << 8) | c.R);
    }

    private static Color ToColor(uint c)
    {
        int R = (int)(c & 0xFF) % 256;
        int G = (int)((c >> 8) & 0xFFFF) % 256;
        int B = (int)(c >> 16) % 256;
        return Color.FromArgb(R, G, B);
    }

When getting the accent color value, USE the crStartColor property, as crAccentColor might return 0, instead of the accent color.

Sample Code:

    public Color GetAccentColor()
    {
      IMMERSIVE_COLOR_PREFERENCE accent = new();
      GetUserColorPreference(ref accent, false);
      return ToColor(accent.crStartColor);

    }

Documentation

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions