0 out of 6 rated this helpful Rate this topic

DwmEnableComposition function

Enables or disables Desktop Window Manager (DWM) composition.

Syntax

HRESULT WINAPI DwmEnableComposition(
  UINT uCompositionAction
);

Parameters

uCompositionAction

DWM_EC_ENABLECOMPOSITION to enable DWM composition; DWM_EC_DISABLECOMPOSITION to disable composition.

Return value

If this function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

Disabling DWM composition disables it for the entire desktop. DWM composition will be automatically enabled when all processes that have disabled composition have called DwmEnableComposition to enable it or have been terminated. The WM_DWMCOMPOSITIONCHANGED notification is sent whenever DWM composition is enabled or disabled.

Examples

The following code example disables DWM composition.



...
HRESULT hr = S_OK;

// Disable DWM Composition 
hr = DwmEnableComposition(DWM_EC_DISABLECOMPOSITION);
if (SUCCEEDED(hr))
{
   // ...
}
...

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008

Header

Dwmapi.h

Library

Dwmapi.lib

DLL

Dwmapi.dll

See also

Enable and Control DWM Composition

 

 

Send comments about this topic to Microsoft

Build date: 9/11/2011

Did you find this helpful?
(2000 characters remaining)
Community Content Add
Annotations FAQ
DWM_EC_DISABLECOMPOSITION internal counter
When you call for example twice: DwmEnableComposition(DWM_EC_DISABLECOMPOSITION) in your application, and you want to re-enable composition, then you need call twice DwmEnableComposition(DWM_EC_ENABLECOMPOSITION). Tested on Win7 SP1 x64 with x86 app. DwmEnableComposition(DWM_EC_DISABLECOMPOSITION); /* Aero disables here */ DwmEnableComposition(DWM_EC_DISABLECOMPOSITION); DwmEnableComposition(DWM_EC_ENABLECOMPOSITION); /* call succeeded but nothing happened */ DwmEnableComposition(DWM_EC_ENABLECOMPOSITION); /* Aero enables here (if no other application requested to disable Aero */ So each call with DWM_EC_DISABLECOMPOSITION must have a matching call with DWM_EC_ENABLECOMPOSITION. But if you call twice DWM_EC_ENABLECOMPOSITION, then you need call only once DWM_EC_DISABLECOMPOSITION. PS. On Windows Developer Preview (a.k.a. Win8) DwmEnableComposition(DWM_EC_DISABLECOMPOSITION) doesn't work.
Return Value
It's worth noting that the return value applies to a request to perform the operation, rather than the operation itself. That is to say, it's entirely possible for DwmEnableComposition(DWM_EC_ENABLECOMPOSITION) to return S_OK and a subsequent DwmIsCompositionEnabled to return FALSE.
Sample for C#
//Alexander Klimoff (http://developer.alexanderklimov)

// See also MSDN Magazine April 2007

[DllImport("dwmapi.dll", PreserveSig = false)]
public static extern int DwmEnableComposition(bool fEnable);

// turn off Aero Glass
DwmEnableComposition(false);