When running this application under Windows XP using a
corresponding manifest-file "BmpDlg.exe.manifest" (to
activate the usage of Luna style), a bug becomes visible:
all checkboxes (and some other controls) won't be displayed
transparent but completely in black color. There were
different approaches to avoid this behaviour, but none of
them seemed to take effect like i was exspecting. So i
burned a few brain cells to find a new way for a workaround.
Simply change the OnCtlColor method the following way:
By doing this, the application forces critical controls to
use explicit background-colors, which are determined
directly from the background-bitmap at the appropriate
position. This won't give you controls which are really
transparent, but looks a lot better than just black boxes.
And: it even works correctly under GUI-transformers
By combining "empty" checkboxes (without text) with a
static text on the right side of this checkbox, you'll get
almost perfect looking controls, even under Luna XP.
PS: Probably my code could be improved by managing the
needed solid brushes at dialog initialization, so that
they'll be created just once for each control and then
being used automatically. My example should be an approach only.
PPS: Don't blame me for my english. I'm not a native
Thank David Forrester.
Your Source Code was very Good. And I used it in my project. Using your code I corrected some function like below. Sorry My English is poor. Have a nice day!
LoadBitmap (LPCTSTR lpszResourceName, LPCTSTR lpszFilename)
// Load the bitmap from a file
HBITMAP hbm = (HBITMAP) LoadImage (NULL, szFilename, IMAGE_BITMAP, 0, 0,
if (hbm == NULL) return FALSE;
// Get the CBitmap object
DeleteObject(hbm); //Add To prevent memory leack
and I recommend MakeWindowRgn()
// Go through all rows
for (int y=0; y<height; y++)
// Start looking at the beginning
row_start = 0;
// Go through all columns
for (int x=0; x<width; x++)
// If this pixel is transparent
if (dcImage.GetPixel(x, y) == m_colTrans)
// If we haven't found an opaque pixel yet, keep searching
if (row_start == x) row_start ++;
// We have found the start (row_start) and end (x) of
// an opaque line. Add it to the region.
y, x, y+1);
rgn.CombineRgn (&rgn, &rgnAdd, RGN_OR);
row_start = x+1;
// If the last pixel is still opaque, make a region.
if (row_start != x)
This class has error while drawing transparent group box and picture static controls.
When you add picture static control with icon, it will be draw incorrect. Namely, almost all icons have transparent region (background), and when you use picture static with icon, this region is dialog background color (background are determinate by dialog background brush). But, CBitmapDialog::OnCtlColor() sets HOLLOW_BRUSH as dialog background brush for all static control (except TRACKBAR_CLASS controls), evidently, picture static draws with BLACK background.
Group box with text header is drawn whit similar error. CBitmapDialog::OnCtlColor() sets TRANSPARENT method for text output. Consequently, text header (caption) will be strikethrough by group box border.
All others static controls are drawn correctly.
P.S. As is well known, .NET window form have background image feature, and if all child static controls has transparent background color then form draws without any artifacts. Does anybody know how it works?