【问题标题】:How can I tell what windows theme I'm using?我如何知道我正在使用什么 Windows 主题?
【发布时间】:2011-02-27 23:27:35
【问题描述】:

我正在尝试让我的应用程序成为一个主题 - 这很简单,如下所示:http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows-theme.aspx

但是,我不知道我现在使用的是什么主题。我使用的是 Windows XP 默认主题,不管它是什么。那篇文章说

指定版本很重要 和公钥令牌

...我从哪里获得这些信息?

【问题讨论】:

  • 出于好奇,您为什么要这样做?您的计划的目的是什么?

标签: c# wpf windows windows-themes


【解决方案1】:

要获取主题名称,您可以调用非托管的 GetCurrentThemeName 方法:

public string GetThemeName()
{
  StringBuilder themeNameBuffer = new StringBuilder(260);
  var error = GetCurrentThemeName(themeNameBuffer, themeNameBuffer.Capacity, null, 0, null, 0);
  if(error!=0) Marshal.ThrowExceptionForHR(error);
  return themeNameBuffer.ToString();
}

[DllImport("uxtheme.dll", CharSet=CharSet.Auto)]
public static extern int GetCurrentThemeName(StringBuilder pszThemeFileName, int dwMaxNameChars, StringBuilder pszColorBuff, int dwMaxColorChars, StringBuilder pszSizeBuff, int cchMaxSizeChars);

可以在GAC中右键主题.dll(如PresentationFramework.Aero)找到版本和公钥令牌(在Exporer中打开c:\Windows\Assembly),也可以使用代码来做.只需使用 AppDomain.CurrentDomain.LoadedAssemblies 遍历所有加载的程序集并找到您想要的:

foreach(Assembly a in AppDomain.CurrentDomain.LoadedAssemblies)
  if(a.Name.StartsWith("PresentationFramework."))
    return a.FullName;

请注意,循环加载的程序集还会告诉您当前的主题名称​​如果当前 AppDomain 中仅加载了一个主题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    相关资源
    最近更新 更多