From: Roger Garrett on

Rob,

That's almost exactly what my code is doing, but the background of the
checkbox (except for the checkbox itself) is completely black. It's possible
that it's sensitive to what version of Windows it's running on. Mine's
running on Windows XP Home Edition. My application has to run properly on all
versions of Windows.

I'm hoping some actual Microsoft guy will take a look at the issue and
provide a comprehensive answer.

Thank you for taking the time to look into it.

- Roger

From: AliR on
My bad on the first message i posted.

Try this:

// TransparentCheckBox.h : implementation file
#pragma once


// CTransparentCheckBox

class CTransparentCheckBox : public CButton
{
DECLARE_DYNAMIC(CTransparentCheckBox)

public:
CTransparentCheckBox();
virtual ~CTransparentCheckBox();

protected:
afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
DECLARE_MESSAGE_MAP()
};



// TransparentCheckBox.cpp : implementation file
//

#include "stdafx.h"
#include "TransparentCheckbox.h"


// CTransparentCheckBox

IMPLEMENT_DYNAMIC(CTransparentCheckBox, CButton)
CTransparentCheckBox::CTransparentCheckBox()
{
}

CTransparentCheckBox::~CTransparentCheckBox()
{
}


BEGIN_MESSAGE_MAP(CTransparentCheckBox, CButton)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_ERASEBKGND()
END_MESSAGE_MAP()



// CTransparentCheckBox message handlers


HBRUSH CTransparentCheckBox::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
}

BOOL CTransparentCheckBox::OnEraseBkgnd(CDC* pDC)
{
return TRUE;
}


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: Roger Garrett on
Alir,

Thank you for the suggestion. I copied your code and made the
CTransactionCheckBox class and then subclassed one of my checkboxes to use it.
Unfortunately, it doesn't work, at least not under Windows XP Home Edition.
My own code, whihc I had previously tried, was very similar to what you
suggested, except it's the underlying window that handles the OnCtlColor
messages. But both approaches have the exact same symptom, namely that it
doesn't work for checkboxes.

I did some testing and found some interesting symptoms:

First of all we note that buttons, radio buttons, and checkboxes are all
variations of the CButton class. That should reasonably mean that they all
behave the same when setting the bkMode to Transparent and handing back a
HollowBrush via CtlColor or OnCtlColor. But they don't. It works fine for
plain buttons and for radio buttons, but it always results in a black
background for checkboxes. This is particularly odd since a radio button and
a checkbox are practically the same thing. They each have a graphic image
(the button) and a text label. It would make sense that the drawing of them
should be handled by the very same Windows code, but apparently they are not.

I also tried a slight variation to my code (the version that handles the
OnCtlColor message within the underlying Window, as opposed to handling the
reflected message directly within the control). My code basically works for
ANY control on my dialog. As a test I took out the code that sets the bkMode
to transparent. It still fails for the checkbox, butnow it also fails for
simple CStatic controls. So there's something that's not interpreting bkMode
and Hollowbrushes properly.
Again, I only have tested this on Windows XP Home Edition. Maybe it works
properly under other versions of Windows.

Which is pretty frustrarting.

I'm going to see if I can get down into the guts of Windows and see where
it's going wrong within the CButton preocessing of its checkbox variation.

Roger Garrett