How to get current Windows Theme Name?

Administrator

VB.NET Forum Admin
Joined
Jun 3, 2004
Messages
1,462
Programming Experience
10+
I'm trying to determine if the theme name is "Vista Aero" as it affects areas of my app which I'll need to disable if this theme is in use. I know whether or not I'm running Vista, but how I do extract the exact "Theme Name" the user has in use?
 
You need to make a pInvoke call to The GetCurrentThemeName Function in uxtheme.dll. Try the code below..

VB.NET:
Public Structure ThemeInfo
    Private Declare Unicode Function GetCurrentThemeName _
        Lib "uxtheme.dll" _
    ( _
        ByVal pszThemeFileName As String, _
        ByVal dwMaxNameChars As Int32, _
        ByVal pszColorBuff As String, _
        ByVal cchMaxColorChars As Int32, _
        ByVal pszSizeBuff As String, _
        ByVal cchMaxSizeChars As Int32 _
    ) As Int32

    Private Const S_OK As Int32 = &H0

    Private m_FileName As String
    Private m_ColorSchemeName As String
    Private m_SizeName As String

    Public Property FileName() As String
        Get
            Return m_FileName
        End Get
        Set(ByVal Value As String)
            m_FileName = Value
        End Set
    End Property

    Public Property ColorSchemeName() As String
        Get
            Return m_ColorSchemeName
        End Get
        Set(ByVal Value As String)
            m_ColorSchemeName = Value
        End Set
    End Property

    Public Property SizeName() As String
        Get
            Return m_SizeName
        End Get
        Set(ByVal Value As String)
            m_SizeName = Value
        End Set
    End Property

    Public Overrides Function ToString() As String
        Return _
            "FileName={" & Me.FileName & _
            "} ColorSchemeName={" & Me.ColorSchemeName & _
            "} SizeName={" & Me.SizeName & "}"
    End Function

    Public Shared ReadOnly Property CurrentTheme() As ThemeInfo
        Get
            Dim ti As New ThemeInfo()
            Const BufferLength As Int32 = 256
            ti.FileName = Strings.Space(BufferLength)
            ti.ColorSchemeName = ti.FileName
            ti.SizeName = ti.FileName
            If _
                GetCurrentThemeName( _
                    ti.FileName, _
                    BufferLength, _
                    ti.ColorSchemeName, _
                    BufferLength, _
                    ti.SizeName, _
                    BufferLength _
                ) = S_OK _
            Then
                ti.FileName = NullTrim(ti.FileName)
                ti.ColorSchemeName = NullTrim(ti.ColorSchemeName)
                ti.SizeName = NullTrim(ti.SizeName)
                Return ti
            Else
                Const Message As String = _
                    "An error occured when attempting to get theme info."
                Throw New Exception(Message)
            End If
        End Get
    End Property

    Private Shared Function NullTrim(ByVal Text As String) As String
        Return _
            Strings.Left( _
                Text, _
                Strings.InStr(Text, ControlChars.NullChar) - 1 _
            )
    End Function
End Structure

Got it from here...

http://dotnet.mvps.org/dotnet/faqs/?id=getactivethemename&lang=en
 
This information (code above) actually provides the following information:

FileName={C:\Windows\resources\themes\Aero\Aero.msstyles} ColorSchemeName={NormalColor} SizeName={NormalSize}

I may have asked for the wrong "terminology". As I look in the "Personalize" section of Vista (formerly display properties) they actually call the names "Color Scheme".

I'm trying to retrieve the names in this selection listbox such as "Windows Aero" "Windows Vista Basic". Let me know if you find out how to retrieve this info.

Thanks!
 
You mean you don't want "Aero", "NormalColor" and "NormalSize", but instead the more decriptive title that is read in dialogs?
The filename given is as I understand a standard win32 resource file (but digitally signed). I read the file format was changed from XP to Vista, but for the former you can for example view it in TGTSofts free ResEdit. Inside I found in TEXTFILE folder the Themes.ini file which lists the displaynames of the theme, colorscheme and fontsize. Not sure how relevant this is exactly for Vista, neither for XP in general since I only got the default Luna theme. In case you try out things, check also with Roeders Resourcer for .Net resources (zip contains versions .Net 1.0,1.1,2.0)
 
The goal was to determine when the Vista Aero theme was in use as it conflicts with the DevExpress Form Skinning mechanism I have in use. I found a solution, again just checking the IndexOf("aero") in the Filename of what you provided. All is well, consider this inquiry resolved! Thanks!
 
To be absolute sure you could:
VB.NET:
[SIZE=2][COLOR=#0000ff][COLOR=black]Dim[/COLOR][/COLOR][/SIZE][COLOR=black][SIZE=2] finfo [/SIZE][SIZE=2]As [/SIZE][SIZE=2]New[/SIZE][SIZE=2] IO.FileInfo(ThemeInfo.CurrentTheme.FileName)
[/SIZE][/COLOR]If IO.Path.GetFileNameWithoutExtension(finfo.Name).ToLower = "aero" _
AndAlso finfo.Directory.Name.ToLower = "aero" Then
'...
End If
 
Back
Top