From: Roger Garrett on
I have a checkbox on a dialog and I want the background portion of it (i.e.
around the outside of the checkbox and behind the text label) to be
transparent so that the underlying color of the dialog shows through.

I handle the dialog's OnCtlColor method and return a hollow brush.

This works just fine for plane old CButtons as well as for the radio button
type of CButton. But it does not work for the checkbox type of CButton. The
checkbox type buttons come up all black, except for the actual checkbox
itself.

What magic do I have to do in order to get it to work for checkboxes?

Roger Garrett

From: AliR on
It can't be done like that. What you have to do is draw the entire control
yourself.

AliR.

"Roger Garrett" <RogerGarrett(a)discussions.microsoft.com> wrote in message
news:B7FC4B0F-D322-4A20-A2DE-A41BDCF91492(a)microsoft.com...
> I have a checkbox on a dialog and I want the background portion of it
(i.e.
> around the outside of the checkbox and behind the text label) to be
> transparent so that the underlying color of the dialog shows through.
>
> I handle the dialog's OnCtlColor method and return a hollow brush.
>
> This works just fine for plane old CButtons as well as for the radio
button
> type of CButton. But it does not work for the checkbox type of CButton.
The
> checkbox type buttons come up all black, except for the actual checkbox
> itself.
>
> What magic do I have to do in order to get it to work for checkboxes?
>
> Roger Garrett
>


From: RobKinney1 on
Oh, sorry about that. I went back to my app that I was doing this on and I
put a check box in it and it displayed properly... I had made other changes
besides just that class include so it took me a minute to figure out why it
was working properly.

I have the following code:

HBRUSH CMySampleDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{

// We don't want all controls using a null brush (goofs
// up the control's paint logic)...
switch ( nCtlColor )
{
case CTLCOLOR_EDIT:
case CTLCOLOR_LISTBOX:
UpdateData(TRUE); // get check box status

default:
pDC->SetBkMode(TRANSPARENT);

// We'll use a different text color depending upon the
// chosen background

// Use a black text color.
pDC->SetTextColor(RGB(0,0,0)); // black

break;

} // switch

// Return our null brush

return m_brHollow;
}

This is bits and pieces I put together from different tutorials on the web.
Now, if I comment out the line:

// pDC->SetBkMode(TRANSPARENT);

.... then my checkbox will have the default windows color instead of showing
through my bitmap properly. Maybe you need to add that line into the
OnCtlColor method...?

Rob K

"Roger Garrett" wrote:

> Rob,
>
> Thanks for offering a solution. The technique described in the article is
> the correct approach for achieving transparent controls. And it works for
> CStatics and buttons and radio buttons (both of which are variations of
> CButton). But it fails to work for checkboxes, which is just another version
> of CButton. It's a very odd problem.
>
> - Roger
>
From: Roger Garrett on
Rob,

Thanks for offering a solution. The technique described in the article is
the correct approach for achieving transparent controls. And it works for
CStatics and buttons and radio buttons (both of which are variations of
CButton). But it fails to work for checkboxes, which is just another version
of CButton. It's a very odd problem.

- Roger

From: RobKinney1 on
Don't know if this will work or not for checkboxes, but I used this article
from CodeProject to make all my text transparent to a bitmap background.

http://www.codeproject.com/staticctrl/TransparentStaticCtrl.asp

I included the class in my project:

#include "TransparentStatic2.h" // used for transparent text

.... And everything worked perfectly.

Rob K

"Roger Garrett" wrote:

> I have a checkbox on a dialog and I want the background portion of it (i.e.
> around the outside of the checkbox and behind the text label) to be
> transparent so that the underlying color of the dialog shows through.
>
> I handle the dialog's OnCtlColor method and return a hollow brush.
>
> This works just fine for plane old CButtons as well as for the radio button
> type of CButton. But it does not work for the checkbox type of CButton. The
> checkbox type buttons come up all black, except for the actual checkbox
> itself.
>
> What magic do I have to do in order to get it to work for checkboxes?
>
> Roger Garrett
>