Link to home
Start Free TrialLog in
Avatar of tomsh
tomsh

asked on

Changing Checkbox Background Color

Hello ,
I would like to know , how can i change the Background Color for my CheckBoxs ?

Tomas
Avatar of nietod
nietod

What OS?

Windows?  Handle the WM_CTLCOLORBTN message.
HI !!
  Neitod is right handle the WM_CTLCLR and in that function return the particular brush u want. That will change the color of the background.
 There are 2 ways either u can derive a class from CButton and overrride the WM_CTLCLR and write there or if u are handling in the Dialog class itself then u have to check for the control id of that check box
e.g if(pWnd->GetDlgCtrlId() == ID_MYCHECKBOX)
     {
         CBrush MyBrush(RGB(255,0,0));
          return MyBrush;
      }
Rather than handle WM_CTRL colour for each child of you window - handle it in the main window with:

ON_WM_CTLCOLOR_REFLECT( ) afx_msg HBRUSH CtlColor ( CDC* pDC, UINT nCtlColor );

ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
nietod - yes of course, got confused about which group I was in.

Apologies :)
No appology needed, I just don't want to see anyone get confused.  tomsh may be programming on the mac or in the windows API and may find your suggestion a little hard to use.
Avatar of tomsh

ASKER

Thanks for your help, Neitod :)