Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Windows 10任务栏托盘图标颜色检测_C#_Windows - Fatal编程技术网

C# Windows 10任务栏托盘图标颜色检测

C# Windows 10任务栏托盘图标颜色检测,c#,windows,C#,Windows,有没有什么方法可以检测出windows 10运行的是哪种颜色和哪种类型的windows样式(我猜是最新的一种,它有明/暗主题-1903) 我有一个托盘图标应用程序,希望根据主题显示一个黑白图标。内置的应用程序可以正确地显示它们,但我不知道如何检测它们。您可以从注册表获取当前主题信息: HKEY\U CURRENT\U USER\Software\Microsoft\Windows\CurrentVersion\Themes (在我的Windows 10操作系统上,GetCurrentThemeN

有没有什么方法可以检测出windows 10运行的是哪种颜色和哪种类型的windows样式(我猜是最新的一种,它有明/暗主题-1903)


我有一个托盘图标应用程序,希望根据主题显示一个黑白图标。内置的应用程序可以正确地显示它们,但我不知道如何检测它们。

您可以从注册表获取当前主题信息:

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正是我需要知道是使用亮图标还是暗图标的关键。