There Be Glass Here!
on 07.11.06, 07:34am in windows • Comments (5)

One of the features that I hear most commonly talked about in Vista is Aero Glass, so I thought I would throw together a quick sample that shows how you can extend the glass region of a window. There’s more information up on MSDN for the curious, but here’s the basic four steps that you need to follow in order to extend glass into a window.
- Include
dwmapi.handdwmapi.libin your project. - Check to see if glass is enabled (using
DwmIsCompositionEnabled()). - Extend the glass ‘frame’ into your window (using
DwmExtendFrameIntoClientArea()). - Paint the area that the glass will go into with an alpha channel of 0 (i.e.- paint it black).
This turns out to be really straightforward. For example, if you wanted to extend the glass on a dialog box by 25 pixels on the top, you could do the following:
case WM_INITDIALOG:
{
BOOL fIsDWMEnabled = FALSE;
DwmIsCompositionEnabled(&fIsDWMEnabled);if (fIsDWMEnabled)
{
MARGINS marginGlass = {0};
marginGlass.cyTopHeight = 25;DwmExtendFrameIntoClientArea(hDlg, &marginGlass);
}
}
break;
Then all that’s needed is to paint the top area black, and fill in the rest with the dialog box color:
case WM_ERASEBKGND:
{
HDC hdcDlg = (HDC)wParam;
RECT rctGlass = {0};
RECT rctNonGlass = {0};GetClientRect(hDlg, &rctGlass);
CopyRect(&rctNonGlass, &rctGlass);rctGlass.bottom = rctGlass.top + 25;
rctNonGlass.top = rctGlass.bottom;FillRect(hdcDlg, &rctGlass, (HBRUSH)GetStockObject(BLACK_BRUSH));
FillRect(hdcDlg, &rctNonGlass, (HBRUSH)GetSysColorBrush(COLOR_3DFACE));
return 1;
}
break;
Now of course, I need to add the disclaimer that using the glass effect is expensive - you should use it sparingly.




Lou Amadio (July 11, 2006 @ 9:14 pm)
Wow Steve, that’s great! How do you paint into that region? Is there a way to have the whole window be “glass” like the sidebar’s gadet picker?
Steve (July 12, 2006 @ 5:42 am)
Set the window margin to -1:
MARGINS marginGlass = {-1};
to do the entire window in glass.
Painting in the glass will be a followup post
art (October 27, 2006 @ 9:16 am)
Where’s hDlg defined from?
Steve (October 28, 2006 @ 6:58 am)
hDlg is the handle to your dialog. In this case, it’s passed in as the first parameter of your DlgProc().
pfisk (May 25, 2007 @ 2:01 pm)
Hello,
How do I access the API’s in order to Create Special Effects With The Desktop Window Manager. In other words, how can I get started?
Thank you
pfisk@sarcom.com