One of the Desktop Window Manager (DWM) signature effects enabled by the DWM is a translucent and blurred non-client area. The DWM APIs enable applications to apply these effects to the client area of their top-level windows.
This topic discusses the following client blur behind scenarios the DWM enables.
- Adding Blur to a Specific Region of the Client Area
- Extending the Window Frame into the Client Area
- Related Topics
Adding Blur to a Specific Region of the Client Area
An application can apply the blur effect behind whole client region of the window or specific sub region. This enables applications to add styled path and search bars that are visually separate from the rest of the application.
The API for this scenario are DwmEnableBlurBehindWindow, DWM Blur Behind Constants, and DWM_BLURBEHIND.
The following sample function, EnableBlurBehind, illustrates how to apply the blur behind the whole window.
HRESULT EnableBlurBehind(HWND hwnd) { HRESULT hr = S_OK; // Create and populate the BlurBehind structure. DWM_BLURBEHIND bb = {0}; // Disable Blur Behind and Blur Region. bb.dwFlags = DWM_BB_ENABLE; bb.fEnable = true; bb.hRgnBlur = NULL; // Disable Blur Behind. hr = DwmEnableBlurBehindWindow(hwnd, &bb); if (SUCCEEDED(hr)) { //do more things } return hr; }
Note that NULL is used for the hRgnBlur. This tells the DWM to apply the blur behind the whole window.
The following image illustrates the blur behind effect applied to the whole window.
To apply the blur behind a sub region, apply a valid HRGN to hRgnBlur and add the DWM_BB_BLURREGION flag to dwFlags.
When you apply the blur behind a sub region of the window, the alpha channel of the window is used for the non blurred area. This can cause an unexpected transparency in the non blurred region of a window. As a result, care should be when you apply a blur effect to a sub region.
Extending the Window Frame into the Client Area
An application can extend the blur of the window frame into the client area. This is useful when you apply the blur effect behind a window with a docked toolbar or visually separate controls from the rest of an application. This functionality is exposed by the DwmExtendFrameIntoClientArea method.
To enable blur using DwmExtendFrameIntoClientArea, MARGINS Structure are used to indicate how much to extend into the client area. The following sample function, ExtendIntoClientBottom, toggles the blur extension on the bottom of the non-client frame into the client area.
HRESULT ExtendIntoClientBottom(HWND hwnd) { //Set margins, extend bottom MARGINS margins = {0,0,0,25}; HRESULT hr = S_OK; //extend frame on bottom of client area hr = DwmExtendFrameIntoClientArea(hwnd,&margins); if (SUCCEEDED(hr)) { //do more things } return hr; }
The following image illustrates the blur behind effect extended into the bottom of the client area.
Also available through the DwmExtendFrameIntoClientArea method is the "sheet of glass" effect where the blur effect is applied to the whole surface of the effect without a visible window border. The following sample demonstrates the "sheet of glass" effect where the client area is rendered without a window border.
HRESULT ExtendIntoClientAll(HWND hwnd) { // Negative margins have special meaning to DwmExtendFrameIntoClientArea. // Negative margins create the "sheet of glass" effect, where the client area // is rendered as a solid surface without a window border. MARGINS margins = {-1}; HRESULT hr = S_OK; // Extend frame across whole window. hr = DwmExtendFrameIntoClientArea(hwnd,&margins); if (SUCCEEDED(hr)) { //do more things } return hr; }
The following image illustrates the blur behind in the "sheet of glass" window style.