Results 1 to 8 of 8

Thread: Detecting windows XP style

  1. #1

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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");
    			}

  3. #3
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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).

  5. #5

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Detecting windows XP style

    Cheers both, it looks like everything i need is included above.

    Thanks.

  6. #6
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Detecting windows XP style

    No, as it checks the OS version first before invoking the API call.

  8. #8
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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
  •  



Click Here to Expand Forum to Full Width