4

I must really know which Windows theme my user is using.
More precisely, Classic, XP, Basic or Aero. (Basic theme as in Vista/7 Windows Basic theme)
I already know how to find if it's aero, but how about the others?


The answer can be in any .NET language (C#, VB.NET or C++).


If you really have to know why on Earth I need to know the theme then here you go:
I have some floating buttons over the caption of a form and I need to change their appearance according to the windows theme.
So far I've managed to find Aero/Classic.


Screen shots of the result, after solving the issue: Minimize to tray button

1

2 Answers 2

5

You can check the registry for the current theme at:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes

under String "CurrentTheme" which has the path to the current theme. below is the code for checking it in C#.

using Microsoft.Win32;

public string GetTheme()
{
  string RegistryKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes";
  string theme;
  theme = (string) Registry.GetValue(RegistryKey, "CurrentTheme", string.Empty);
  theme = theme.Split('\\').Last().Split('.').First().ToString();
  return theme;
}
34
  • My guess is that this will not be able to detect situations where Aero is disabled, e.g. remote desktop, VNC mirror driver. What would help would be for @Vercas to indicate what he wants to do with the information. Dec 19, 2010 at 10:01
  • 1
    This is not an option. I need lightning fast solutions. Registries and generally file IO aren't fast enough. Imagine moving a form in Seven/Vista. The form follows the cursor instantly, unlike XP. This could mean reading that registry key even a thousand times per second.
    – Vercas
    Dec 19, 2010 at 12:10
  • 1
    @Vercas @Shekhar_Pro Also this isn't going to work on XP. No such key as CurrentTheme in that location. Registry keys are an implementation detail and subject to change from version to version. Dec 19, 2010 at 15:26
  • 1
    @David Thanx for mentioning, i know it may not work in xp, an upvote for your answer, have a good day :) Dec 20, 2010 at 13:44
  • 1
    @David you are absolutely right, Almost every software in computer use registry. Remember even windows use registry for checking themes and Desktop settings. Dec 20, 2010 at 13:51
3

You can check whether themes are active by calling IsAppThemed/IsThemeActive and then check for Aero by calling DwmIsCompositionEnabled. There may well be other ways of doing this!!

EDIT

The logic would be:

  1. Can I import IsAppThemed and IsThemeActive? If no then I must be in Windows Classic (Win9x or Win2k).
  2. What does IsAppThemed and IsThemeActive return? If false then I must be in Windows Classic.
  3. Can I import DwmIsCompositionEnabled? If no then I must be XP themed.
  4. What does DwmIsCompositionEnabled return? If true then I am Aero, otherwise I am Windows Basic.
25
  • IsThemeActive is the equivalent of Application.RenderWithVisualStyles(C#), which doesn't quite work...
    – Vercas
    Dec 18, 2010 at 18:56
  • @Vercas See my edit. It is conceivable that asking these questions from inside a .net app might have different results. I've no idea how WinForms, WPF etc. are implemented and how themes impact on .net GUI apps. Dec 18, 2010 at 19:03
  • But what if IsThemeActive always returns false? :|
    – Vercas
    Dec 18, 2010 at 19:24
  • 1
    Definitely WinForms. I will look into VisualStyleInformation.IsEnabledByUser.
    – Vercas
    Dec 19, 2010 at 12:12
  • 1
    @Vercas Indeed that is what I am saying. You use the DrawThemeBackground API. Dec 20, 2010 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.