我如何知道我使用的是什么 Windows 主题? [英] How can I tell what windows theme I'm using?

查看:13
本文介绍了我如何知道我使用的是什么 Windows 主题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to make my application force a theme - this is straightforward as shown here: http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows-theme.aspx

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

However, I don't know what theme I'm using now. I'm using the Windows XP default theme, whatever that may be. That article says

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

It's important to specify the version and the public key token

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

...where do I get that information?

推荐答案

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

To get the theme name you can call the unmanaged GetCurrentThemeName method:

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

You can find the version and public key token by right-clicking the theme .dll (such as PresentationFramework.Aero) in the GAC (open c:\Windows\Assembly in Exporer), or you can use code to do it. Just loop through all loaded assemblies using AppDomain.CurrentDomain.LoadedAssemblies and find the one you want:

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

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

Note that looping through the loaded assemblies will also tell you the current theme name if only one theme has been loaded in the current AppDomain.

这篇关于我如何知道我使用的是什么 Windows 主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆