Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This topic presents a set of best practices for using the Desktop Window Manager (DWM) APIs.
This topic contains the following sections:
If your application handles dots per inch (dpi) scaling, you can declare an application as dpi-aware and prevent automatic scaling by setting the dpi-aware flag in the program's manifest or by calling the SetProcessDPIAware function during program initialization.
With DWM composition turned on, obscured applications no longer receive WM_PAINT messages and are not asked to re-render. Each window's content is already available to compose the screen image.
Top-level WS_EX_TRANSPARENT windows should be combined with a WS_EX_LAYERED style for the purposes of hit testing. WS_EX_TRANSPARENT in the classic sense, without redirection, is useful for child windows in a hierarchy of windows that belong to the same thread, but is not intended for top-level windows.
Use regions or layering to create shaped or blended windows. Note that in Windows Vista and later versions of Windows, custom drawing only part of a top-level window will not provide the desired stale content in undrawn regions.
APIs such as GetDCOrgEx can be used to determine certain actual values. If you have a device context (DC) for a redirected window, the origin returned by GetDCOrgEx will not match the origin of your window on the screen. The origin will instead be the origin of the back-buffer surface for your window: (0, 0).
When all else fails, disable window rendering by calling the DwmSetWindowAttribute function.
Avoid drawing directly to the primary display surface. Doing so will force the DWM to disable composition until your application releases the primary device surface.
Evaluate whether your application must provide its own double buffering. The DWM effectively double buffers content and presents the window in a single frame.
Avoid reading from or writing to a display DC. Although supported by DWM, we do not recommend it because of decreased performance.
Avoid drawing in the non-client area. Although this area can be accessed by the application, and drawing there is supported by the Microsoft Win32 API, doing this can cause the window to lose any glass border it has.
Avoid mixing Windows Graphics Device Interface (GDI) and Microsoft DirectX unless they do not overlap. If mixing is necessary, either draw the GDI content into a DirectX software surface and combine them before composing to the screen, or else draw them in separate windows.
Use BitBlt or StretchBlt function instead of Windows GDI+ to present your drawing for rendering. GDI+ renders one scan line at a time with software rendering. This can cause flickering in your applications.
Rendering the blur-behind effect is a resource-intensive operation for both the CPU and the graphics processing unit (GPU). Application developers are urged to consider the implications of using client-area blur so that it does not consume excessive resources. You should use particular caution in the following cases:
Events
Apr 8, 3 PM - May 28, 7 AM
Sharpen your AI skills and enter the sweepstakes to win a free Certification exam
Register now!