开发者

How to get the Windows 7 theme name

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:\Win开发者_高级运维dows\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);


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜