views:

53

answers:

1

Hi,

I have some code that attempts to test whether my application is running with the themes set. Here's the C# code:

internal class NativeMethods
{

   [DllImport("comctl32", CharSet = CharSet.Auto, SetLastError = true)]
   internal static extern uint DllGetVersion(ref DLLVERSIONINFO pdvi);

   [StructLayout(LayoutKind.Sequential)]
   internal struct DLLVERSIONINFO
   {
    public uint cbSize;
    public uint dwMajorVersion;
    public uint dwMinorVersion;
    public uint dwBuildNumber;
    public uint dwPlatformID;
   }

            internal static bool IsThemed()
   {
    bool retval = false;

    if ((Environment.OSVersion.Version.Major >= 5 &&
      Environment.OSVersion.Version.Minor >= 1) ||
      Environment.OSVersion.Version.Major > 5)
    {
     bool appThemed = NativeMethods.IsAppThemed();
     bool themeActive = NativeMethods.IsThemeActive();

     if (appThemed && themeActive)
     {
      DLLVERSIONINFO dvi = new DLLVERSIONINFO();
      dvi.cbSize = (uint)Marshal.SizeOf(dvi);

      NativeMethods.DllGetVersion(ref dvi);

      retval = (dvi.dwMajorVersion >= 6);
     }
    }
}

This code works great for my needs under Windows XP, 2003 and Vista. However, when I try it under Windows 7, where I'm running Aero, the call to DllGetVersion returns a value less than 6. When I debug my application and look at the version number of comctl32 under the debugger (modules window), it shows a version number greater than 6 is loaded. Why does my code return a different number?

Thanks,

Notre

A: 

Looking at MSDN for DllGetVersion(), it sounds like this might not be the best way to do what you're trying to do. Since this isn't an API function, it's possible that this changed in Win7 somehow and can't be called in the same way.

If you're using WinForms, you could try calling Application.RenderWithVisualStyles - that sounds like it's doing what you're trying to do above.

Andy
This looks promising, Andy. I'll wait to see if anyone else wants to comment, but Application.RenderWithVisualStyles looks like it might work for me.