SetUserColorPreference (uxtheme)
Last changed: -37.101.209.105

.
Summary
SetUserColorPreference will set the current theme Accent color and the Start menu color through uint numbers representing colors inside the IMMERSIVE_COLOR_PREFERENCE structure

C# Signature:

[DllImport("uxtheme", EntryPoint = "#122")]
static extern int SetUserColorPreference(ref IMMERSIVE_COLOR_PREFERENCE pcpPreference, bool fForceSetting);

VB Signature:

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

User-Defined Types:

[StructLayout(LayoutKind.Sequential)]

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

Notes:

None for now

Tips & Tricks:

//To convert Colors from their UINT form 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);
    }

Sample Code:

[DllImport("uxtheme", EntryPoint = "#122")]
static extern int SetUserColorPreference(ref IMMERSIVE_COLOR_PREFERENCE pcpPreference, bool fForceSetting);

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

[StructLayout(LayoutKind.Sequential)]
  private struct IMMERSIVE_COLOR_PREFERENCE
  {
     public uint dwColorSetIndex;
     public uint crStartColor;
     public uint crAccentColor;
  }

private void SetAccentColor(Color c)
    {
        IMMERSIVE_COLOR_PREFERENCE temp = new IMMERSIVE_COLOR_PREFERENCE
        {
        crAccentColor = ToUint(c),
        dwColorSetIndex = 0,
        crStartColor = ToUint(c)
        };
        SetUserColorPreference(ref temp, true);
    }

Documentation