I need to subclass a checkbox, and that is of CButton class. I tried that, and overwrite OnPaint(), however the check box disappears, I guess that is because I would need to paint the checkbox as well, well, that is beyond my knowledge, so I tried to overwrite OnCtlColor, however that doesn't get called.

One post said that I would need to set the ownerdraw flag, I tried that it doesn't work with the following:

OOPS... I forgot to draw the check. you need to add that, but
that just amount to drawing some lines

March 8th, 2004, 09:47 AM

jiac

Can you also tell me how to draw the check boxes? That is the part that I have the least idea of.

Thanks.
Jiac

March 8th, 2004, 01:30 PM

VladimirF

You could use DrawFrameControl() with DFCS_BUTTONCHECK.
However, couldn't you just set a font and color, and NOT do ownerdraw stuff?

March 9th, 2004, 05:07 PM

souldog

I didn't know you could change the color of the text of a CButton
without making it owner drawn.
Can you? If you can then just do that.

If you do go the owner drawn route, then don't do what I did
above.

It seems that BS_AUTOCHECKBOX and BS_OWNERDRAW
do not go together well, but I did not try creating the button
outside of the resource editor

The easiest way to do owner drawn is to create a regular owner
drawn button and use DrawFrameControl() control draw the
check and box. Or you can draw the box and check yourself.
With this method you have to keep track of the state of the check yourself.
Let me know if you need it and I will give you the code

March 11th, 2004, 10:18 AM

jiac

Can you tell me how to change the font size and font color?

In addition, for custom draw, if I were to use DFCS_BUTTONCHECK, would user's check /uncheck still be trapped? How to do that?

Thanks.
Jiac

March 11th, 2004, 01:11 PM

VladimirF

Make a CFont data member in your dialog.
In OnInitDialog(), create the font you like (look up CreateFont(...)), and set it to be used for your checkbox (using SetFont(...)).
Create OnCtlColor() handler and check if the window pointer passed in is your CheckBox, then set the text color to whatever using pDC->SetTextColor(...);

March 11th, 2004, 01:43 PM

souldog

Darn :blush:

I didn't realize OnCtrlColor worked when a CButton has the
BS_AUTOCHECKBOX style.

That is the way to go.

March 11th, 2004, 02:25 PM

VladimirF

Quote:

Originally posted by souldog
OnCtrlCOlor does not work for CButton objects. That is the problem

Yes, I corrected myself.
Try using that method to change the text color for a regular button.

That is why i got confused

March 14th, 2004, 09:06 PM

peterbing

BS_AUTOCHECKBOX and BS_OWNERDRAW can not work together
if you change the buttong to BS_OWNERDRAW style, it is not CheckBox any more. after you have changed the style to BS_OWNERDRAW , the function SetCheck(), GetCheck() will not work.

March 14th, 2004, 09:53 PM

souldog

That is correct, you have to manage that yourself.
But in this case it is not needed.

May 4th, 2004, 02:55 PM

Xatrix

Sorry for bumping this, but I have the very same problem. How can I change the color of the font and background in a CheckBox using _only_ Windows API functions/calls/messages/etc/etc.. ?