Discussion:
Transparent background color for a checkbox
(too old to reply)
Salman Mughal
2007-02-01 19:16:02 UTC
Permalink
In a Win32 app (no MFC) running on XPsp2, I have a window with a custom
background image (bitmap) and several controls on it (static text, edit
boxes, buttons, etc.). I would like all of the text drawn on the window to
have a transparent background so the image is not obscured. For the static
controls, I'm handling the WM_CTLCOLORSTATIC message and returning a
transparent brush using the following method:

LRESULT CMyWindow::OnControlColorStatic(HDC hdc, HWND hwndControl)
{
LRESULT ret = 0L;

if (hwndControl == one_of_the_static_labels_on_my_page)
{
SetBkMode(hdc, TRANSPARENT);
ret = (LRESULT)GetStockObject(HOLLOW_BRUSH);
}
else
ret = (LRESULT)GetStockObject(WHITE_BRUSH);

return ret;
}

This works fine. When I try to do the same thing with a checkbox button on
the window, however (handling the WM_CTLCOLORBTN message), I still get the
checkbox background drawn white, not transparent. Is there something
additional I need to do? Not sure it's relevant, but the button style is
BS_AUTOCHECKBOX.
b***@mail.ru
2007-02-01 21:26:09 UTC
Permalink
You need to processing WM_CTLCOLORBTN, but there can be troubles:

The WM_CTLCOLORBTN message is sent to the parent window of a button
before drawing the button. The parent window can change the button's
text and background colors. However, only owner-drawn buttons respond
to the parent window processing this message.

so button should have BS_OWNERDRAW

The text color of a check box or radio button applies to the box or
button, its check mark, and the text. The focus rectangle for these
buttons remains the system default color (typically black). The text
color of a group box applies to the text but not to the line that
defines the box. The text color of a push button applies only to its
focus rectangle; it does not affect the color of the text.


On Feb 2, 12:16 am, Salman Mughal
Post by Salman Mughal
In a Win32 app (no MFC) running on XPsp2, I have a window with a custom
background image (bitmap) and several controls on it (static text, edit
boxes, buttons, etc.). I would like all of the text drawn on the window to
have a transparent background so the image is not obscured. For the static
controls, I'm handling the WM_CTLCOLORSTATIC message and returning a
LRESULT CMyWindow::OnControlColorStatic(HDC hdc, HWND hwndControl)
{
LRESULT ret = 0L;
if (hwndControl == one_of_the_static_labels_on_my_page)
{
SetBkMode(hdc, TRANSPARENT);
ret = (LRESULT)GetStockObject(HOLLOW_BRUSH);
}
else
ret = (LRESULT)GetStockObject(WHITE_BRUSH);
return ret;
}
This works fine. When I try to do the same thing with a checkbox button on
the window, however (handling the WM_CTLCOLORBTN message), I still get the
checkbox background drawn white, not transparent. Is there something
additional I need to do? Not sure it's relevant, but the button style is
BS_AUTOCHECKBOX.
Christian ASTOR
2007-02-01 23:17:54 UTC
Permalink
Post by Salman Mughal
This works fine. When I try to do the same thing with a checkbox button on
the window, however (handling the WM_CTLCOLORBTN message), I still get the
checkbox background drawn white, not transparent. Is there something
additional I need to do? Not sure it's relevant, but the button style is
BS_AUTOCHECKBOX.
BS_AUTOCHECKBOX => WM_CTLCOLORSTATIC
Salman Mughal
2007-02-06 18:59:01 UTC
Permalink
I did try handling the checkbox in the same way as the static controls (in
the same handler for WM_CTLCOLORSTATIC), but then instead of getting a
transparent background it ends up being black.
Post by Christian ASTOR
Post by Salman Mughal
This works fine. When I try to do the same thing with a checkbox button on
the window, however (handling the WM_CTLCOLORBTN message), I still get the
checkbox background drawn white, not transparent. Is there something
additional I need to do? Not sure it's relevant, but the button style is
BS_AUTOCHECKBOX.
BS_AUTOCHECKBOX => WM_CTLCOLORSTATIC
Christian ASTOR
2007-02-06 19:47:38 UTC
Permalink
Post by Salman Mughal
I did try handling the checkbox in the same way as the static controls (in
the same handler for WM_CTLCOLORSTATIC), but then instead of getting a
transparent background it ends up being black.
If it's black, it's certainly themed (manifest)
If so, DrawThemeParentBackground() + WM_PRINTCLIENT handling.
Salman Mughal
2007-02-20 23:27:10 UTC
Permalink
This post might be inappropriate. Click to display it.
Christian ASTOR
2007-02-23 06:06:01 UTC
Permalink
Post by Salman Mughal
As I'm not that familiar with GDI drawing code, could you provide some more
details: am I supposed to call DrawThemeParentBackground() in the WM_PAINT
handler of the parent window? And call it with the HWND of the control in
question (the checkbox)? And finally, in the WM_PRINTCLIENT handler, do I
just draw my custom background again in the provided DC?
DrawThemeParentBackground() can be called in WM_CTLCOLORSTATIC.
In WM_PAINT & WM_PRINTCLIENT, you can call the same drawing function
((HDC)wParam as parameter)
(DrawThemeParentBackground() changes the viewport origin then sends
WM_PRINTCLIENT)

Continue reading on narkive:
Loading...