Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: transparent CheckBox/radioBox

478 views
Skip to first unread message

David Ching

unread,
Feb 12, 2008, 10:37:10 AM2/12/08
to
"D@na" <D...@discussions.microsoft.com> wrote in message
news:BBF5389F-C6CD-4152...@microsoft.com...
> hello All..
>
> there is something weird in my project when dealing with transparent
> checkbox or radio box.. I wanna have a transparent-background CheckBox and
> RadioBox
> I ve tried using owner draw and implement WM_CTLCLR. The checkbox/radiobox
> background will turn to black if i set my project Unicode-support. But,
> everything work well if i work in a non-unicode project. Since i need to
> support
> Unicode, its so troublesome.
> I dont get what's happening, so need your expertist ..FYI, Im using visual
> studio 2005
>
> thanks in advance
>

I have UNICODE project with transparent checkboxes and radio buttons. But
only the text to the right of these controls are transparent. The actual
checkbox/radio button can't be transparent (or at least I haven't found a
way). In fact, I have code that has:

HBRUSH CBaseWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CWnd::OnCtlColor(pDC, pWnd, nCtlColor);

DWORD dwStyle = pWnd->GetStyle();
if ( dwStyle &
(BS_AUTORADIOBUTTON | BS_RADIOBUTTON | BS_AUTOCHECKBOX |
BS_CHECKBOX) )
{
// Radio buttons and checkboxes have ugly gray backgrounds that
// stick out when placed over a white background; paint the
background
// in white for a better blend
hbr = (HBRUSH) GetStockObject (WHITE_BRUSH);
}

return hbr;
}


So I explicitly set the color of the checkbox/radio button here.

-- David


AliR (VC++ MVP)

unread,
Feb 12, 2008, 11:12:33 AM2/12/08
to
This is the way I implemented a transparent checkbox/radiobutton
As with David's, mine only has the text part transparent. If you want the
actual box transparent, you will have to create your own control from
scratch.

// CTransparentCheckBox

class CTransparentCheckBox : public CButton
{
DECLARE_DYNAMIC(CTransparentCheckBox)

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

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


//////////////////////////////////////////////////////////////////////////////////////////////////
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.

D@na

unread,
Feb 12, 2008, 8:19:00 PM2/12/08
to
thanks for the reply , AliR& David..

i implemented exactly the same way.. but as you said, cannot make the
checkbox/radiobox background transparent. what I'm courious at is that it
work well in non-Unicode program.
1. Supposing that Unicode use different library from a non-unicode one, does
it mean that it has different implementation for this case? whats happening
here?
2. for making it from the scratch, coudl you kinly advise some clue?

here was my implementation for the CButton implemented class. i have made
sure that the message was properly captured.

//----------------------------------------------------------------------
class radiobutton : public CButton
{
DECLARE_DYNAMIC(radiobutton)
public:
radiobutton();
virtual ~radiobutton();

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

//------------------------------------------
IMPLEMENT_DYNAMIC(radiobutton, CButton)
radiobutton::radiobutton()
{
}
radiobutton::~radiobutton()
{
}

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

// radiobutton message handlers
BOOL radiobutton::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
return TRUE;
}

HBRUSH radiobutton::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
// TODO: Change any attributes of the DC here
pDC->SetBkMode(TRANSPARENT);
return (HBRUSH)GetStockObject(HOLLOW_BRUSH);
}
//----------------------------------


thanks..
D@na

David Ching

unread,
Feb 12, 2008, 9:39:42 PM2/12/08
to

"D@na" <D...@discussions.microsoft.com> wrote in message
news:A44B7414-3DB3-4B25...@microsoft.com...

> thanks for the reply , AliR& David..
>
> i implemented exactly the same way.. but as you said, cannot make the
> checkbox/radiobox background transparent. what I'm courious at is that it
> work well in non-Unicode program.
> 1. Supposing that Unicode use different library from a non-unicode one,
> does
> it mean that it has different implementation for this case? whats
> happening
> here?
> 2. for making it from the scratch, coudl you kinly advise some clue?
>

The only thing that comes to mind is if your program is manifested and calls
InitCommonControls(Ex) to utilize the version 6 common controls. Maybe
something there has changed regarding the transparent background. I seem to
recall some difference in behavior between UNICODE and ANSI apps regarding
this, but do not recall the details. If you learn more, please report here.

Thanks,
David


jaca...@gmail.com

unread,
Feb 15, 2008, 4:09:06 AM2/15/08
to
On 12 Lut, 16:37, "David Ching" <d...@remove-this.dcsoft.com> wrote:

Hi,

the solution that works for me in Unicode mode is drawing the
background in the CtlColor implementation of your class AND returning
a HOLLOW_BRUSH. You don't need to do anything in OnEraseBkgnd in that
case.

Jacek

David Ching

unread,
Feb 15, 2008, 9:57:43 AM2/15/08
to
<jaca...@gmail.com> wrote in message
news:699e803a-406b-49c2...@s8g2000prg.googlegroups.com...

> Hi,
>
> the solution that works for me in Unicode mode is drawing the
> background in the CtlColor implementation of your class AND returning
> a HOLLOW_BRUSH. You don't need to do anything in OnEraseBkgnd in that
> case.
>
> Jacek

Great, thanks for updating us!

-- David


D@na

unread,
Feb 20, 2008, 3:34:01 PM2/20/08
to

"David Ching" wrote:
>
> The only thing that comes to mind is if your program is manifested and calls
> InitCommonControls(Ex) to utilize the version 6 common controls. Maybe
> something there has changed regarding the transparent background. I seem to
> recall some difference in behavior between UNICODE and ANSI apps regarding
> this, but do not recall the details. If you learn more, please report here.
>
> Thanks,
> David
>

investigating the manifest file, seems that the unicode project utilize
version 6 common control while non-unicode don't. could you please tel me
how to unutilize version6 common control?

thanks

D@na

unread,
Feb 20, 2008, 8:11:23 PM2/20/08
to
David...

thanks to your reply that really got to the point. I just resolved my
problem :)
my project was manifested and utilized version 6 common control when i
called InitCommonControls().
what i do then is using my own manifest file (instead of let the project
generate one for me) for creating and embedding the final manifest.

Thanks
Dana

David Ching

unread,
Feb 21, 2008, 12:27:58 AM2/21/08
to
"D@na" <D...@discussions.microsoft.com> wrote in message
news:65B6E57B-E9D6-494A...@microsoft.com...

> David...
>
> thanks to your reply that really got to the point. I just resolved my
> problem :)
> my project was manifested and utilized version 6 common control when i
> called InitCommonControls().
> what i do then is using my own manifest file (instead of let the project
> generate one for me) for creating and embedding the final manifest.
>
> Thanks
> Dana
>

I'm very glad to hear that, Dana! :-) Thanks for letting us know.

-- David


yawarmaajed

unread,
May 20, 2010, 12:50:39 PM5/20/10
to
Hi Dana, I came across the exact same problem with unicode vs. ansi version incompatibility between transparency in check box buttons. I am using Visual Studio 2008 and I don't know how to generate a manifest file of my own, if I were to, how would I tackle the side by side assemblies, dev studio generates one for me after looking for DLLs at the right places and putting their versions in the manifest correctly.

Please do let me know
Yawar

Dn wrote:

David...thanks to your reply that really got to the point.
20-Feb-08

David...

thanks to your reply that really got to the point. I just resolved my
problem :)
my project was manifested and utilized version 6 common control when i
called InitCommonControls().
what i do then is using my own manifest file (instead of let the project
generate one for me) for creating and embedding the final manifest.

Thanks
Dana

"D@na" wrote:

Previous Posts In This Thread:

On Tuesday, February 12, 2008 5:39 AM
Dn wrote:

transparent CheckBox/radioBox
hello All..

there is something weird in my project when dealing with transparent
checkbox or radio box.. I wanna have a transparent-background CheckBox and
RadioBox
I ve tried using owner draw and implement WM_CTLCLR. The checkbox/radiobox
background will turn to black if i set my project Unicode-support. But,
everything work well if i work in a non-unicode project. Since i need to
support
Unicode, its so troublesome.
I dont get what's happening, so need your expertist ..FYI, Im using visual
studio 2005

thanks in advance

On Tuesday, February 12, 2008 10:37 AM
David Ching wrote:

Re: transparent CheckBox/radioBox


"D@na" <D...@discussions.microsoft.com> wrote in message

news:BBF5389F-C6CD-4152...@microsoft.com...

I have UNICODE project with transparent checkboxes and radio buttons. But
only the text to the right of these controls are transparent. The actual
checkbox/radio button can't be transparent (or at least I haven't found a
way). In fact, I have code that has:

HBRUSH CBaseWnd::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CWnd::OnCtlColor(pDC, pWnd, nCtlColor);

DWORD dwStyle = pWnd->GetStyle();
if ( dwStyle &
(BS_AUTORADIOBUTTON | BS_RADIOBUTTON | BS_AUTOCHECKBOX |
BS_CHECKBOX) )
{
// Radio buttons and checkboxes have ugly gray backgrounds that
// stick out when placed over a white background; paint the
background
// in white for a better blend
hbr = (HBRUSH) GetStockObject (WHITE_BRUSH);
}

return hbr;
}


So I explicitly set the color of the checkbox/radio button here.

-- David

On Tuesday, February 12, 2008 11:12 AM

// CTransparentCheckBox

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

CTransparentCheckBox::~CTransparentCheckBox()
{
}

// CTransparentCheckBox message handlers


AliR.

"D@na" <D...@discussions.microsoft.com> wrote in message
news:BBF5389F-C6CD-4152...@microsoft.com...

On Tuesday, February 12, 2008 8:19 PM
Dn wrote:

thanks for the reply , AliR& David..i implemented exactly the same way..


thanks for the reply , AliR& David..

i implemented exactly the same way.. but as you said, cannot make the
checkbox/radiobox background transparent. what I'm courious at is that it
work well in non-Unicode program.
1. Supposing that Unicode use different library from a non-unicode one, does
it mean that it has different implementation for this case? whats happening
here?
2. for making it from the scratch, coudl you kinly advise some clue?

here was my implementation for the CButton implemented class. i have made


thanks..
D@na

"AliR (VC++ MVP)" wrote:

On Tuesday, February 12, 2008 9:39 PM
David Ching wrote:

Re: transparent CheckBox/radioBox


"D@na" <D...@discussions.microsoft.com> wrote in message

news:A44B7414-3DB3-4B25...@microsoft.com...

The only thing that comes to mind is if your program is manifested and calls
InitCommonControls(Ex) to utilize the version 6 common controls. Maybe
something there has changed regarding the transparent background. I seem to
recall some difference in behavior between UNICODE and ANSI apps regarding
this, but do not recall the details. If you learn more, please report here.

Thanks,
David

On Friday, February 15, 2008 9:57 AM
David Ching wrote:

Re: transparent CheckBox/radioBox


Great, thanks for updating us!

-- David

On Saturday, February 16, 2008 4:57 AM
jacadcap wrote:

Re: transparent CheckBox/radioBox


On 12 Lut, 16:37, "David Ching" <d...@remove-this.dcsoft.com> wrote:

Hi,

the solution that works for me in Unicode mode is drawing the
background in the CtlColor implementation of your class AND returning
a HOLLOW_BRUSH. You don't need to do anything in OnEraseBkgnd in that
case.

Jacek

On Wednesday, February 20, 2008 3:34 PM
Dn wrote:

Re: transparent CheckBox/radioBox
"David Ching" wrote:

investigating the manifest file, seems that the unicode project utilize
version 6 common control while non-unicode don't. could you please tel me
how to unutilize version6 common control?

thanks

On Wednesday, February 20, 2008 8:11 PM
Dn wrote:

David...thanks to your reply that really got to the point.
David...

thanks to your reply that really got to the point. I just resolved my
problem :)
my project was manifested and utilized version 6 common control when i
called InitCommonControls().
what i do then is using my own manifest file (instead of let the project
generate one for me) for creating and embedding the final manifest.

Thanks
Dana

"D@na" wrote:

On Thursday, February 21, 2008 12:27 AM
David Ching wrote:

Re: transparent CheckBox/radioBox
I am very glad to hear that, Dana! :-) Thanks for letting us know.

-- David


Submitted via EggHeadCafe - Software Developer Portal of Choice
WPF Report Engine, Part 4
http://www.eggheadcafe.com/tutorials/aspnet/5ac799db-385f-431a-8a45-8b37cb7f3186/wpf-report-engine-part-4.aspx

0 new messages