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);
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());
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());
}
{
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.
02/28/2010 - 05:37
Thank you very much!
09/24/2010 - 16:03
thanks :)
05/23/2011 - 16:46
I need it in VB.Net... pls.. I really need it.
felixcomp@hotmail.com
05/24/2011 - 04:31
@felixcomp
translating C# to VB.NET isn't that hard... do some work yourself
Add Comment
[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.