Vista glass answers and DwmEnableBlurBehindWindow

Fri, August 11, 2006, 06:06 PM under Windows | Vista
While I have explained how to get glass on Vista with C# (twice), I did leave two open questions (hint: read the last paragraph of my last glass blog post or the stuff below won't make any sense).

Kenny Kerr steps up to the challenge and answers both questions on his article here!
For the answer to "why black" scroll down to the "Painting" section under the form with the red blob on it. For the question of why R=G=B fails, scroll slightly further down under the "Can you see me" forms.

If you don't care about the answers to the questions I posed then still go read Kenny's entry for the excellent clarification on the terminology at the beginning of his article. Even if you are not interested in the answers, terminology or even glass, then go read it for the coverage of other DWM topics. Go!

The other thing Kenny covers is a relevant glass API that I haven't talked about here before: DwmEnableBlurBehindWindow

I won't go into *any* description or give any context as I expect you'll read that on Kenny's blog. But after you've read the native approach, here is a simplified example of a managed version:

Create a new VS2005 winforms project on Vista, delete all Form1 files, add a new empty code file, and paste into it the following (then hit F5):
namespace GlassMoth
{
public class Form2 : System.Windows.Forms.Form
{
public Form2()
{
this.ClientSize = new System.Drawing.Size(200, 200);

System.IntPtr hr =
CreateEllipticRgn(30, 30, 170, 170); //or CreateRectRgn

DWM_BLURBEHIND dbb;
dbb.fEnable = true;
dbb.dwFlags = 1 2;
dbb.hRgnBlur = hr;
dbb.fTransitionOnMaximized = false;
DwmEnableBlurBehindWindow(this.Handle, ref dbb);
}

protected override void OnPaintBackground(
System.Windows.Forms.PaintEventArgs e)
{
e.Graphics.FillRectangle(
new System.Drawing.SolidBrush(System.Drawing.Color.Black),
new System.Drawing.Rectangle(30, 30, 140, 140));
}

#region pinvokes
[System.Runtime.InteropServices.DllImport("gdi32")]
private static extern System.IntPtr CreateEllipticRgn(
int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);

public struct DWM_BLURBEHIND
{
public int dwFlags;
public bool fEnable;
public System.IntPtr hRgnBlur;//HRGN
public bool fTransitionOnMaximized;
}

[System.Runtime.InteropServices.DllImport("dwmapi")]
private static extern int DwmEnableBlurBehindWindow(
System.IntPtr hWnd, ref DWM_BLURBEHIND pBlurBehind);
#endregion
}
}
Enjoy (believe it or not, I do have one final blog entry to do on glass... stay tuned)!
Thursday, 20 March 2008 11:05:00 (Pacific Standard Time, UTC-08:00)
Your or fell off:

dbb.dwFlags = 1 | 2;
Anonymous
Comments are closed.