开发者

How can I tell what windows theme I'm using?

开发者 https://www.devze.com 2023-01-02 14:03 出处:网络
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

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

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 informatio开发者_如何学运维n?


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);

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;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消