Menu

[Win] Change text color on a GroupBox

2003-02-04
2012-09-26
  • Nobody/Anonymous

    I have seen some discussion here and at other forums about using WM_CTLCOLORBTN and i know i should not use it to change the colors of a PUSHBUTTON but what about a GroupBox?

    I am trying to set the color of the text of a button with a BS_GROUPBOX style with absolutely no success.

    Look, at WM_CREATE...

    --------------------------------------------------------------------------------
          FirstGroup = CreateWindowEx (0, TEXT ("button"), TEXT("Status:"),
           WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
            9, 238, 346, 143, mainWindow, (HMENU) 1200, hInstance, NULL) ;
    --------------------------------------------------------------------------------

    At WM_COMMAND i deal with all my buttons, including one that selects a color for that GroupBox...

    --------------------------------------------------------------------------------
    case IDC_BUTTONSTATUSGROUPTXTCOLOR:
    MessageBox (NULL, TEXT ("Step 1 ok!"), "DEBUGGING", MB_ICONERROR) ;
    if(ChooseColor(&choosecolor)) {
    currentcolorref = choosecolor.rgbResult;
    statusgrouptxtcolorref = currentcolorref;
    InvalidateRect(mainWindow, NULL, TRUE);     
    return 0;  
    }
    --------------------------------------------------------------------------------

    And im taking care of WM_CTLCOLORBTN here:

    --------------------------------------------------------------------------------
            case WM_CTLCOLORBTN:     
            if(colorhwnd==FirstGroup) {
            MessageBox (NULL, TEXT ("Step 2 ok!"), "DEBUGGING", MB_ICONERROR) ;

            SetTextColor((HDC)wParam, statusgrouptxtcolorref);
            SetBkMode((HDC)wParam, OPAQUE);
            SetBkColor((HDC)wParam, tabbgcolorref);
            logbrush.lbColor=tabbgcolorref;
            DeleteObject(hbrush);
            hbrush=CreateBrushIndirect(&logbrush);
            return (long)hbrush;
            return 0;
          }
    --------------------------------------------------------------------------------

    Up to now i can change the color of everything in my app except for the groupboxes text, you guys have any idea?

     
    • Nobody/Anonymous

      Just a note:

      At WM_CTLCOLORBTN, I forgot to tell you that
      the first line of that block is
      colorhwnd=(HWND)lParam;

      Sorry about that, im sleepy.

       
    • Nobody/Anonymous

      Solved: To change the text color on a button with a BS_GROUPBOX style you have to intercept case WM_CTLCOLORSTATIC not WM_CTLCOLORBTN.

      Sux but works :)

       
    • Nobody/Anonymous

      Now that you mention this..

      When I return 0 on WM_CTLCOLORSTATIC or WM_CTLCOLORBTN I get a memory error. I MUST return a brush. Another thing is that WM_CTLCOLORBTN does nothing for me. I can't change the text color for instance. Do you have any clues?

      -Jay

       
    • Nobody/Anonymous

      Hey Jay, I guess i found something interesting...

      "Usually the WM_CTL* messages work just fine for other controls but not buttons.
      When you handle the WM_CTLCOLORBTN message, you can change the button's background color, which is hidden behind the button. This is left over from win 3.1"

      So, no option but to use Owner Drawun buttons, work a little more on WM_DRAWITEM and thats it :(

      Theres a good example on Owner Drawn button on Petzold if i remember correctly. 

       
    • Nobody/Anonymous

      BTW, does anyone has any idea on how to change the bg color of the parts of a StatusBar ?

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.