Programmatically (first-time!) enable aero theme/desktop composition
Question
I want to enable desktop composition on a Windows 7 machine programmatically (preferrable C#) and already tried to do it with the infamous DwmEnableComposition
P/Invoke. However, this does not seem to work if DWM has never been enabled (and the performance test has not run). I can, however, enable DWM via the "Personalization" control panel w/o running the performance test.
My question therefore is: how can I do the same programmatically? And a second question: how can I achieve that a change in the setting is persistent (e. g. if I set DwmEnableComposition(false)
on a machine that has DWM enabled, it is re-enabled once the application exits)?
Solution
I found a less nasty solution than my first one: Invoking winsat dwm
will turn on Aero automatically once it finishes and if the hardware supports it - and it does not change the wallpaper etc.
OTHER TIPS
The answer is: You cannot do that.
Microsoft does not expose a programmatic way for programs to enable or disable desktop composition on the user's machine.
The reason they don't provide an API is that programs might use it.
In the past Microsoft trusted developers not to do the wrong thing. That has changed
DwmEnableComposition
is only for your application to temporarily disable DWM if you aren't compatible with composition. It cannot be used to turn on composition, when the user has already turned it off.
Any computer sold in the last 5 years is graphically capable of using composition, and Windows turns it on by default if its supported. The only reason it would be turned off is:
- the user turned it off
- another application is running that doesn't support composition
In either case: you should not (and therefor cannot) turn it on.
You cannot do that.