|
-
Nov 17th, 2005, 05:32 AM
#1
Thread Starter
Frenzied Member
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.
-
Nov 17th, 2005, 09:50 AM
#2
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");
}
-
Nov 17th, 2005, 10:18 AM
#3
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...
Last edited by penagate; Nov 17th, 2005 at 10:22 AM.
-
Nov 17th, 2005, 10:45 AM
#4
Re: Detecting windows XP style
 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).
-
Nov 17th, 2005, 11:31 AM
#5
Thread Starter
Frenzied Member
Re: Detecting windows XP style
Cheers both, it looks like everything i need is included above.
Thanks.
-
Nov 18th, 2005, 07:14 PM
#6
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?
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Nov 18th, 2005, 07:17 PM
#7
Re: Detecting windows XP style
No, as it checks the OS version first before invoking the API call.
-
Nov 18th, 2005, 07:37 PM
#8
Re: Detecting windows XP style
I see, interesting
I didnt know that
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|