Thread: Color Checkboxes

  1. #1
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56

    Question Color Checkboxes

    How do you color a checkbox? Coloring the text of a checkbox is not a problem, but not the box itself. Success has been eluding me and I am not sure where to start.
    SpEcIeS

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Hmm I haven't tried this, but if one of the WM_CTLCOLOR messages doesn't handle checkboxes, you could always made an owner drawn box and just handle drawing it manually.

  3. #3
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56
    Hmm I haven't tried this, but if one of the WM_CTLCOLOR messages doesn't handle checkboxes, you could always made an owner drawn box and just handle drawing it manually.
    Unfortunatly this did not work for me, but perhaps I have not applied it correctly. My static text boxes work well with the WM_CTLCOLORSTATIC message, but after going through all of the messages I have come to a wall. (I even did the obvious ones that would not work)

    Building my own checkbox sounds very complicated for me, and I really do not know where to start.

    You input is greatly appreciated.
    SpEcIeS

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Have you tried WM_CTLCOLORBTN?

  5. #5
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56
    Quote Originally Posted by anonytmouse
    Have you tried WM_CTLCOLORBTN?
    Yes, WM_CTLCOLORBTN was tried, but perhaps it was not applied correctly. Do you, or anyone else, have an example?
    SpEcIeS

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    For non-push button 'button' controls, like checkboxes, handle the parent's WM_CTLCOLORSTATIC. See also this page; the information is good for winxp, too.
    Code:
    case WM_CTLCOLORSTATIC:
      {
      int nID=GetDlgCtrlID((HWND)lParam);
      switch (nID)
        {
        case IDC_CHECKBOX:
          SetTextColor((HDC)wParam,RGB(255,0,0)); /*red*/
          return (LRESULT)GetStockObject(LTGRAY_BRUSH);
        case IDC_ANOTHER_CHECKBOX:
          SetTextColor(HDC)wParam,RGB(0,255,0)); /*green*/
          return (LRESULT)GetStockObject(BLACK_BRUSH);
        }
      }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User SpEcIeS's Avatar
    Join Date
    Aug 2004
    Posts
    56
    Nice piece of code Ken. However, this was accomplished, but not in such a nice format. What I was looking for was the box its self being colored. For example: the check mark being yellow and the background to the box being black.

    Perhaps I am faced with creating my own checkbox, and that sounds painful.

    Thanks for your reply though. It was greatly appreciated.
    SpEcIeS

Popular pages Recent additions subscribe to a feed