首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Windows 10任务栏托盘图标的颜色检测

Windows 10任务栏托盘图标的颜色检测
EN

Stack Overflow用户
提问于 2019-07-03 08:26:40
回答 1查看 680关注 0票数 4

有没有任何方法可以检测到哪种颜色和哪种类型的windows 10运行的是windows 10(我猜是最新的一种,其中有轻/暗主题-1903年)。

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-07-03 10:05:39

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

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes

( GetCurrentThemeName api在我的Windows10OS上返回InstallVisualStyle值)

声明:

代码语言:javascript
复制
[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);

要获得当前主题颜色(重音颜色),您可以:

代码语言:javascript
复制
[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;
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56865923

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档