Question

I have some UI in VB 2005 that looks great in XP Style, but goes hideous in Classic Style.

Any ideas about how to detect which mode the user is in and re-format the forms on the fly?


Post Answer Edit:

Thanks Daniel, looks like this will work. I'm using the first solution you posted with the GetCurrentThemeName() function.

I'm doing the following:

Function Declaration:

 Private Declare Unicode Function GetCurrentThemeName Lib "uxtheme" (ByVal stringThemeName As System.Text.StringBuilder, ByVal lengthThemeName As Integer, ByVal stringColorName As System.Text.StringBuilder, ByVal lengthColorName As Integer, ByVal stringSizeName As System.Text.StringBuilder, ByVal lengthSizeName As Integer) As Int32

Code Body:


Dim stringThemeName As New System.Text.StringBuilder(260)
Dim stringColorName As New System.Text.StringBuilder(260)
Dim stringSizeName As New System.Text.StringBuilder(260)

GetCurrentThemeName(stringThemeName, 260, stringColorName, 260, stringSizeName, 260) MsgBox(stringThemeName.ToString)

The MessageBox comes up Empty when i'm in Windows Classic Style/theme, and Comes up with "C:\WINDOWS\resources\Themes\luna\luna.msstyles" if it's in Windows XP style/theme. I'll have to do a little more checking to see what happens if the user sets another theme than these two, but shouldn't be a big issue.

Was it helpful?

Solution

Try using a combination of GetCurrentThemeName (MSDN Page) and DwmIsCompositionEnabled

I linked the first to PInvoke so you can just drop it in your code, and for the second one you can use the code provided in the MSDN comment:

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern bool DwmIsCompositionEnabled();

See what results you get out of those two functions; they should be enough to determine when you want to use a different theme!

OTHER TIPS

Personally, I use the following to see if the app is running under themed:

if (Application.RenderWithVisualStyles)
{
    // you're themed
}

There's the IsThemeActive WinAPI function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top