Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Windows 7 theme name

Tags:

c#

winapi

Windows 7 comes with several built-in themes. They can be accessed by right-clicking the desktop and choosing Personalize. Under Personalize, there is a section names "Aero Themes" containing themes like "Architecture" "Nature" and so on.

I tried using uxtheme.dll's GetCurrentThemeName, but it's actually giving the style name: "C:\Windows\resources\Themes\Aero\Aero.msstyles" unless my current theme is set to Windows Basic, in which case it returns an empty string. Is there an API that actually returns the theme name, like "Nature" "Architecture" etc...?

The code I tried is as follows:

[DllImport("uxtheme", ExactSpelling = true, CharSet = CharSet.Unicode)] 
public extern static Int32 GetCurrentThemeName(StringBuilder stringThemeName, 
    int lengthThemeName, StringBuilder stringColorName, int lengthColorName, 
    StringBuilder stringSizeName, int lengthSizeName);

    StringBuilder stringThemeName = new StringBuilder(260);
    StringBuilder stringColorName = new StringBuilder(260);
    StringBuilder stringSizeName = new StringBuilder(260);

    Int32 s = GetCurrentThemeName(stringThemeName, 260,stringColorName, 260,stringSizeName, 260);
like image 838
user577240 Avatar asked Nov 04 '22 18:11

user577240


1 Answers

After taking a look at the MSDN documentation it looks like GetThemeDocumentationProperty might be what you are looking for.

You'll want to use it in conjunction with the theme file (which you alreayd have found in the registry) as well as by passing in the SZ_THDOCPROP_DISPLAYNAME as the second parameter of the method.

In addition here is a site that has the c# method wrapper for the p/invoke call: http://www.java2s.com/Open-Source/CSharp/2.6.4-mono-.net-core/System.Windows.Forms/System/Windows/Forms/VisualStyles/UXTheme.cs.htm

Hope that helps.

like image 102
Brian Dishaw Avatar answered Nov 14 '22 22:11

Brian Dishaw