Created
June 6, 2020 10:20
-
-
Save smourier/d9de36c49e19aa9923d5143965057405 to your computer and use it in GitHub Desktop.
Dumps uxtheme immersive colors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.InteropServices; | |
namespace ConsoleApp18 | |
{ | |
public class Program | |
{ | |
static void Main() | |
{ | |
GetUserColorPreference(out var pref, false); | |
var i = 0; | |
do | |
{ | |
var ptr = GetImmersiveColorNamedTypeByIndex(i); | |
if (ptr == IntPtr.Zero) | |
break; | |
var nt = Marshal.PtrToStructure<IMMERSIVE_COLOR_NAMED_TYPES>(ptr); | |
var color = GetColorFromPreference(ref pref, nt.colorType, false, IMMERSIVE_HC_CACHE_MODE.IHCM_USE_CACHED_VALUE); | |
Console.WriteLine(nt + " => 0x" + color.ToString("X8")); | |
i++; | |
} | |
while (true); | |
} | |
[DllImport("uxtheme", EntryPoint = "#100")] | |
static extern IntPtr GetImmersiveColorNamedTypeByIndex(int index); | |
[DllImport("uxtheme")] | |
static extern int GetUserColorPreference(out IMMERSIVE_COLOR_PREFERENCE pcpPreference, bool fForceReload); | |
[DllImport("uxtheme")] | |
static extern uint GetColorFromPreference(ref IMMERSIVE_COLOR_PREFERENCE cpcpPreference, int colorType, bool fNoHighContrast, IMMERSIVE_HC_CACHE_MODE mode); | |
private enum IMMERSIVE_HC_CACHE_MODE | |
{ | |
IHCM_USE_CACHED_VALUE = 0, | |
IHCM_REFRESH = 1, | |
} | |
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] | |
private struct IMMERSIVE_COLOR_NAMED_TYPES | |
{ | |
public string pszColorType; | |
public int colorType; | |
public override string ToString() => pszColorType + " (" + colorType + ")"; | |
} | |
[StructLayout(LayoutKind.Sequential)] | |
private struct IMMERSIVE_COLOR_PREFERENCE | |
{ | |
public uint dwColorSetIndex; | |
public uint crStartColor; | |
public uint crAccentColor; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment