C# Windows 10任务栏托盘图标颜色检测
有没有什么方法可以检测出windows 10运行的是哪种颜色和哪种类型的windows样式(我猜是最新的一种,它有明/暗主题-1903)C# Windows 10任务栏托盘图标颜色检测,c#,windows,C#,Windows,有没有什么方法可以检测出windows 10运行的是哪种颜色和哪种类型的windows样式(我猜是最新的一种,它有明/暗主题-1903) 我有一个托盘图标应用程序,希望根据主题显示一个黑白图标。内置的应用程序可以正确地显示它们,但我不知道如何检测它们。您可以从注册表获取当前主题信息: HKEY\U CURRENT\U USER\Software\Microsoft\Windows\CurrentVersion\Themes (在我的Windows 10操作系统上,GetCurrentThemeN
我有一个托盘图标应用程序,希望根据主题显示一个黑白图标。内置的应用程序可以正确地显示它们,但我不知道如何检测它们。您可以从注册表获取当前主题信息: HKEY\U CURRENT\U USER\Software\Microsoft\Windows\CurrentVersion\Themes (在我的Windows 10操作系统上,GetCurrentThemeNameapi返回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;
谢谢你让我走上这条路!在我看来,计算机\HKEY\U CURRENT\U USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\SystemUseSignetheme正是我需要知道是使用亮图标还是暗图标的关键。