DWM Blur Behind Overview

DWM Blur Behind Overview

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.

Note  Windows Vista Home Basic edition does not support the transparent glass effect. Areas that would typically render with the transparent glass effect on other Windows Vista editions are rendered opaque.

This topic discusses the following client blur behind scenarios the DWM enables.

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.

Blur Behind 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.

Extended Bottom Frame

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.

Extended Frames for Sheet of Glass

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值