要获取主题名称,您可以调用非托管 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;
请注意,循环加载的程序集还将告诉您当前的主题名称if当前AppDomain中仅加载了一个主题。