有没有任何方法可以检测到哪种颜色和哪种类型的windows 10运行的是windows 10(我猜是最新的一种,其中有轻/暗主题-1903年)。
我有一个托盘图标应用程序,并希望显示一个黑白图标取决于主题。内置的应用程序正确地显示了它们,但我不知道如何检测它。
发布于 2019-07-03 10:05:39
您可以从注册表中获取当前主题信息:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes
( GetCurrentThemeName api在我的Windows10OS上返回InstallVisualStyle值)
声明:
[DllImport("UxTheme.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern int GetCurrentThemeName(StringBuilder pszThemeFileName, int cchMaxNameChars, StringBuilder pszColorBuff, int cchMaxColorChars, StringBuilder pszSizeBuff, int cchMaxSizeChars);要获得当前主题颜色(重音颜色),您可以:
[DllImport("Uxtheme.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "#95")]
public static extern int GetImmersiveColorFromColorSetEx(int dwImmersiveColorSet, int dwImmersiveColorType, bool bIgnoreHighContrast, int dwHighContrastCacheMode);
[DllImport("Uxtheme.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "#96")]
public static extern int GetImmersiveColorTypeFromName(IntPtr pName);
[DllImport("Uxtheme.dll", SetLastError = true, CharSet = CharSet.Auto, EntryPoint = "#98")]
public static extern int GetImmersiveUserColorSetPreference(bool bForceCheckRegistry, bool bSkipCheckOnFail);
int nColorSystemAccent = GetImmersiveColorFromColorSetEx(GetImmersiveUserColorSetPreference(false, false), GetImmersiveColorTypeFromName(Marshal.StringToHGlobalUni("ImmersiveSystemAccent")), false, 0);
System.Drawing.Color colorSystemAccent = ColorTranslator.FromWin32(nColorSystemAccent);
// Test color
this.BackColor = colorSystemAccent;https://stackoverflow.com/questions/56865923
复制相似问题