Drawing on glass windows

.NET Framework 4.0 and drawing on Aero Glass issue

In my application I have a form which I tweak by using the DWM API’s method DwmExtendFrameIntoClientArea to extend the height of the Aero Glass Title Bar so that part of my form client area is drawn on the Aero frame. To achieve this effect, I also draw a black rectangle on the part of the client area which is ‘over’ the glass frame so that it appears transparent, as many online articles suggest. This worked pretty well under Windows Vista/Windows 7 but as I downloaded VS 2010 and used the .NET Framework 4.0 as my trarget framework to build my application, this approach no longer works. The problem is that the black rectangle is visible, i.e. the black color is no longer considered transparent when drawing on Aero glass. Does anyone have an idea what might be wrong with that and how it can be overcome?

2 Answers 2

The answer to this question is described here: http://msdn.microsoft.com/en-us/magazine/cc163435.aspx#S6 with solutions for C#.

Excerpt from the linked page (in case the link is down):

Using glass as a background on your window is a bit tricky. If you render anything naturally opaque (such as GDI functions), you’ll get your item rendered on glass, though sometimes with unexpected results. If you want to actually blend rendering into the glass surface, you’ll need to take advantage of functionality that utilizes the alpha channel of colors, such as GDI+, Windows Presentation Foundation, or the Windows XP Theme API.

One particular gotcha is that rendering a GDI item in black uses the bit pattern 0x00000000-which also happens to be a completely transparent black if you are using an alpha channel. This means that if you draw with a black GDI brush or pen you’ll get a transparent color, not a black one. The biggest problem this presents is when you try to use the default text color in a control of a text label that sits on the glass area. Since the default text color is usually black, the DWM will consider this to be transparent and the text will be written in the glass incorrectly.

Читайте также:  Расширение дискового пространства linux
Оцените статью