Detecting windows XP style
My company developed some custom controls for use in our applications and they look very nice too. However some of them don't work if Windows XP is using a classic theme rather than XP Theme.
Is it possible to detect what theme windows XP is using so that we can render the controls differently depending on the theme in use?
Cheers.
Re: Detecting windows XP style
Code:
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\ThemeManager");
if(key.GetValue("ThemeActive").ToString()=="1")
{
MessageBox.Show("Themes enabled");
}
Re: Detecting windows XP style
To detect whether an XP system is using visual styles:
Code:
using System.Runtime.InteropServices;
// --------------------------------------------------------
[DllImport("uxtheme")]
private static extern int OpenThemeData (
IntPtr hWnd,
[MarshalAs(UnmanagedType.LPWStr)] string lpszClassList
);
[DllImport("uxtheme")]
private static extern int CloseThemeData (
int hTheme
);
// --------------------------------------------------------
public static bool IsXPThemed()
{
// Only invoke the API functions if running on Win XP+
if ((Environment.OSVersion.Platform == PlatformID.Win32NT) &&
(Environment.OSVersion.Version.Major >= 5) &&
(Environment.OSVersion.Version.Minor >= 1))
{
int hTheme = OpenThemeData(IntPtr.Zero, "ExplorerBar");
if (hTheme > 0)
{
CloseThemeData(hTheme);
return true;
}
}
return false;
}
@ Mendhak: I prefer not to use the registry - it can be edited...
Re: Detecting windows XP style
Quote:
Originally Posted by Fishcake
Is it possible to detect what theme windows XP is using so that we can render the controls differently depending on the theme in use?
To detect WHICH visual style is in use, if there is one, you can use the following API call and wrapping function:
Code:
[DllImport("uxtheme")]
private static extern int GetCurrentThemeName (
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszThemeFileName,
int dwMaxNameChars,
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszColorBuff,
int cchMaxColorChars,
[MarshalAs(UnmanagedType.LPWStr)] StringBuilder lpszSizeBuff,
int cchMaxSizeChars
);
// --------------------------------------------------------
public static string XPThemeName ()
{
if (IsXPThemed())
{
StringBuilder buffer = new StringBuilder(260);
GetCurrentThemeName(null, 0, buffer, 260, null, 0);
return buffer.ToString();
}
return "n/a";
}
The default cheesy theme names are "NormalColor" (blue), "Metallic" (silver), and "Homestead" (disgusting olive green).
Re: Detecting windows XP style
Cheers both, it looks like everything i need is included above.
Thanks.
Re: Detecting windows XP style
doesnt your code require the uxtheme dll to be present (cuz of dllImport)? that doesnt give errors on a win98 machine?
Re: Detecting windows XP style
No, as it checks the OS version first before invoking the API call.
Re: Detecting windows XP style
I see, interesting
I didnt know that