C# Snippet Tutorial - Determining if Aero is Enabled [Beginner]


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.

Comments