Sunday, April 28, 2013

Aero Enabler Disabler (AeroED)

There is a good reason why I needed to create "Aero Enabler Disabler" application for my own purposes.

- I'm lazy. I don't want to remember where it is enabled or disabled. Too many clicks, hence I created this application. I've pinned this to my task bar so its easy to launch it whenever needed.

- Netflix. Silverlight has tearing problems when playing videos if Aero is disabled. If Aero composition is enabled it means that the GPU is used to draw the desktop, hence the tearing problem is gone after enabling it.

- When playing Battlefield 3 (and other games), I want to disable Aero because I don't want to see "Keep current settings..." message and to be thrown to the desktop when I'm having my best killing spree going on. This is pretty annoying when it happens.

This is how the AeroED looks like
From pinvoke.net I found out that I can enable and disable Aero with one call to DwmEnableComposition. This of course wasn't enough because I need to know what is the current state of Aero Composition when application is launched and I then found DwmIsCompositionEnabled.


 using System;  
 using System.Windows.Forms;  
   
 namespace Aero_Enabled_Disabler  
 {  
   using System.Runtime.InteropServices;  
   
   public partial class FormAeroEnablerDisabler : Form  
   {  
     [DllImport("dwmapi.dll")]  
     private static extern int DwmIsCompositionEnabled(out bool enabled);  
   
     [DllImport("dwmapi.dll", PreserveSig = false)]  
     public static extern void DwmEnableComposition(CompositionAction uCompositionAction);  
   
     [Flags]  
     public enum CompositionAction : uint  
     {  
       /// <summary>  
       /// To enable DWM composition  
       /// </summary>  
       DWM_EC_DISABLECOMPOSITION = 0,  
       /// <summary>  
       /// To disable composition.  
       /// </summary>  
       DWM_EC_ENABLECOMPOSITION = 1  
     }  
   
     public FormAeroEnablerDisabler()  
     {  
       InitializeComponent();  
   
       if (Environment.OSVersion.Version.Major < 6)  
       {  
         MessageBox.Show("This application works only on windows 7 and vista");  
       }  
       else  
       {  
         bool enabled;  
         DwmIsCompositionEnabled(out enabled);  
         if (enabled)  
         {  
           buttonEnablerDisabler.Text = "Disable";  
         }  
         else  
         {  
           buttonEnablerDisabler.Text = "Enable";  
         }  
       }  
     }  
   
     private void buttonEnablerDisabler_Click(object sender, EventArgs e)  
     {  
       if (buttonEnablerDisabler.Text == "Disable")  
       {  
         buttonEnablerDisabler.Text = "Enable";  
         DwmEnableComposition(CompositionAction.DWM_EC_DISABLECOMPOSITION);  
       }  
       else  
       {  
         buttonEnablerDisabler.Text = "Disable";  
         DwmEnableComposition(CompositionAction.DWM_EC_ENABLECOMPOSITION);  
       }  
     }  
   }  
 }  
Source code (C# .NET)

Download AeroED source code 
Download AeroED executable