I have a application that uses the Aero glass effect, so each pixel has an alpha value in addition to red, green, and blue values. I have one custom-draw control that has a solid white background (alpha = 255). I would like to draw solid text on the control using the GDI text functions. However, these functions set the alpha value to an arbitrary value, causing the text to translucently show whatever window is beneath my application's.
After calling rendering the text, I would like to go through all of the pixels in the control and set their alpha value back to 255. What's the best way to do that?
I haven't had any luck with the BitBlt
, GetPixel
, and SetPixel
functions. They appear to be oblivious to the alpha value.
Here are other solutions that I have considered and rejected:
- Draw to a bitmap, then copy the bitmap to the device: With this approach, the text rendering does not make use of the characteristics of the monitor (e.g., ClearText). If you know of a way to get GDI to render the text to the bitmap exactly as it would render to the screen, that would also solve my problem.
- Use GDI+ for text rendering: This application originally used GDI+ for text rendering (before I started working on Aero support). I switched to GDI because of difficulties I encountered trying to accurately measure strings with GDI+. I'd rather not switch back.
- Set the Aero region to avoid the control in question: My application's window is actually a child window of a different application running in a different process. I don't have direct control over the Aero settings on the top-level window.
The application is written in C# using Windows Forms, though I'm not above using Interop to call Win32 API functions.