2010-06-04 98 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中。

相關問題