Come faccio a sapere quale tema di Windows sto usando?
-
24-10-2019 - |
Domanda
Sto cercando di fare la mia forza di applicazione di un tema - questo è semplice come illustrato di seguito: http://arbel.net/blog/archive/2006/11/03/Forcing-WPF-to-use-a-specific- Windows theme.aspx
Comunque, io non so cosa tema che sto usando ora. Sto usando il tema di default di Windows XP, qualunque essa sia. Questo articolo dice
E 'importante specificare la versione e la chiave pubblica del token
... dove posso ottenere queste informazioni?
Soluzione
Per ottenere il nome del tema è possibile chiamare il metodo GetCurrentThemeName non gestito:
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);
È possibile trovare la versione e la chiave pubblica gettone facendo clic destro del dll tema (come ad esempio PresentationFramework.Aero) nella GAC ??(c aperto: \ Windows \ Assembly in Exporer), oppure è possibile utilizzare il codice per farlo . ciclo solo attraverso tutte le assemblee caricato utilizzando AppDomain.CurrentDomain.LoadedAssemblies e trovare quello che si desidera:
foreach(Assembly a in AppDomain.CurrentDomain.LoadedAssemblies)
if(a.Name.StartsWith("PresentationFramework."))
return a.FullName;
Si noti che il ciclo attraverso le assemblee caricati vi dirà anche il nome del tema corrente se solo tema è stata eseguita in AppDomain corrente.