Enable and Control DWM Composition
The Desktop Window Manager (DWM) composition APIs provide several functions that provide functionality for setting and querying for basic information that is use by the DWM. These APIs enable you to query and change the composition state. Additionally, you can set and query the rendering policy for different DWM window attributes.
The topic contains the following sections:
Disabling DWM Composition
Because DWM uses the graphics processing unit (GPU) for desktop composition, certain applications might have to disable DWM for compatibility. Applications that take full control of the desktop, such as games that run in full-screen mode, must determine whether the DWM is enabled and if it is, disable it. To do this, two functions are needed: DwmIsCompositionEnabled and DwmEnableComposition.
A call to DwmEnableComposition with fEnable set to DWM_EC_DISABLECOMPOSITION disables DWM composition until either the calling process has shutdown or composition has been re-enabled by calling DwmEnableComposition, with fEnable set to DWM_EC_ENABLECOMPOSITION. DWM composition restarts automatically as soon as all applications that have disabled composition have shutdown or manually re-enabled composition through DwmEnableComposition.
Note The DWM will automatically disable composition when an application attempts to draw directly to the primary display surface. Composition will be disabled until the primary device surface is released by that application.
Retrieving the Colorization Information
The color of the non-client region of windows is handled by the current system color theme. The colorization value is provided though the DWM APIs to enable applications to match client user interface (UI) with the system color theme.
The APIs to access this colorization value and monitor the color change are DwmGetColorizationColor and WM_DWMCOLORIZATIONCOLORCHANGED.
The following example demonstrates how to monitor the color change and access the new color.
...
case WM_DWMCOLORIZATIONCOLORCHANGED:
{
g_currColor = (DWORD)wParam;
g_opacityblend = (BOOL)lParam;
}
break;
...
Controlling Non-Client Region Rendering
Two of the visual effects DWM enables are transparency of the non-client region of a window and transition effects. Some applications might have to disable or re-enable these effects for styling or compatibility reasons. The following API are used to manage transparency and transition effect behavior:
To retrieve the current non-client rendering state for an application's window, use DwmGetWindowAttribute with the DWMWA_NCRENDERING_ENABLED attribute. The following example shows a typical DwmGetWindowAttribute call.
BOOL enabled = FALSE;
HRESULT hr = DwmGetWindowAttribute(hwnd, DWMWA_NCRENDERING_ENABLED, &enabled, sizeof(enabled));
Note Each
DWMWINDOWATTRIBUTE has an implied type associated with it. Refer to each enumeration member for detailed information.
DwmSetWindowAttribute enables applications to set the non-client area rendering policy. It also determines how the application should handle DWM transition effects.
The following sample disables non-client area rendering.
HRESULT DisableNCRendering(HWND hwnd)
{
HRESULT hr = S_OK;
DWMNCRENDERINGPOLICY ncrp = DWMNCRP_DISABLED;
// Disable non-client area rendering on the window
hr = DwmSetWindowAttribute(hwnd, DWMWA_NCRENDERING_POLICY, &ncrp, sizeof(ncrp));
if (SUCCEEDED(hr))
{
// ...
}
return hr;
}
In addition to controlling the non-client area rendering, DwmSetWindowAttribute can also control DWM transition effects. Transition behavior can be set by using DWMWA_TRANSITIONS_FORCEDISABLED as the dwAttribute attribute.
Messaging
The following APIs provide notification of DWM events. These API can be used to monitor changes such as the composition state changes and system color theme changes.