C# Snippet Tutorial - Determining if Aero is Enabled

Skill

C# Snippet Tutorial - Determining if Aero is Enabled

Posted in:

Recently I was working on a project and the UI required minor tweaks depending on whether or not Aero was enabled. Fortunately, I came across an MSDN forum topic with the solution, so I thought I'd share.

There's no way to do it within .NET, so you'll have to use DLLImport to bring in the Windows API function, DwmIsCompositionEnabled.

[DllImport("dwmapi.dll", EntryPoint="DwmIsCompositionEnabled")]
public static extern int DwmIsCompositionEnabled(out bool enabled);

Once you've got it imported, using it is pretty straight forward.

bool aeroEnabled;
DwmIsCompositionEnabled(out aeroEnabled);
Console.WriteLine("Area Enabled: " + aeroEnabled.ToString());

This function is only supported in versions of Windows starting with Vista, so it might be a good idea to check the OS version before using it.

if (Environment.OSVersion.Version.Major > 5)
{
  bool aeroEnabled;
  DwmIsCompositionEnabled(out aeroEnabled);
  Console.WriteLine("Area Enabled: " + aeroEnabled.ToString());
}

You can see a table of all Windows versions on the Windows Wikipedia page.

den123
02/28/2010 - 05:37

Thank you very much!

reply

Anonymous
09/24/2010 - 16:03

thanks :)

reply

felixcomp
05/23/2011 - 16:46

I need it in VB.Net... pls.. I really need it.

felixcomp@hotmail.com

reply

Basuro
05/24/2011 - 04:31

@felixcomp

translating C# to VB.NET isn't that hard... do some work yourself

reply

Add Comment

Put code snippets inside language tags:
[language] [/language]

Examples:
[javascript] [/javascript]
[actionscript] [/actionscript]
[csharp] [/csharp]

See here for supported languages.

Javascript must be enabled to submit anonymous comments - or you can login.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.