2010-06-04 101 views
3

我试图让我的应用程序强制一个主题 - 这是直接的,如下所示:http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific-Windows-theme.aspx我如何知道我使用的是什么Windows主题?

但是,我不知道我现在使用什么主题。我正在使用Windows XP默认主题,无论可能如何。那篇文章说

指定版本 ,它是重要的公钥标记

...我在哪里可以得到这些信息?

+0

出于好奇,你为什么要这么做?你的程序的目的是什么? – 2010-06-05 11:14:14

回答

4

为了获得主题名称,你可以调用非托管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); 

您可以找到的版本和公钥令牌右键单击该主题.dll文件(如PresentationFramework.Aero) GAC(在Exporer中打开c:\ Windows \ Assembly),或者您可以使用代码来执行此操作。

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

注意,通过加载的程序集循环还会告诉你目前的主题名称如果主题只有一个已经被加载:在所有加载的程序集使用AppDomain.CurrentDomain.LoadedAssemblies,找到你想要的只是环在当前的AppDomain中。

相关问题