Win32 API - Group Box Control

This is a discussion on Win32 API - Group Box Control within the Windows Programming forums, part of the Platform Specific Boards category; Hi people, I was just wondering how do you change the background text colour (on the caption) on a group ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Location
    England
    Posts
    5

    Win32 API - Group Box Control

    Hi people,
    I was just wondering how do you change the background text colour (on the caption) on a group box control? aswell as the font and text colour itself.

    This is how I create a group box:
    Code:
    CreateWindow("BUTTON", "Foobar...", WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
                 10,            /* X Position */
                 10,            /* Y Position */
                 250,           /* X Width */
                 250,           /* Y Height */
                 hwnd, (HMENU) -1, hInstance, NULL);
    and this is how I catch WM_CTLCOLORBTN:
    Code:
    case WM_CTLCOLORBTN:
        SetTextColor((HDC)wParam, RGB(255, 0, 0));
        SetBkColor((HDC)wParam, RGB(0, 0, 0));
        SetBkMode((HDC)wParam, TRANSPARENT); 
        return(LRESULT) GetStockObject(NULL_BRUSH);
    Any help would be appreciated,
    Cheers

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Contrary to msdn documentation the WM_CTLCOLORBTN message is useless. The colours of some button types can be modified by handling the parent's WM_CTLCOLORSTATIC message; for groupboxes only the text colour can be changed using this approach.

    To change fonts send a WM_SETFONT message to the window in question.

    Since a groupbox is transparent it usually takes on the colour of what's underneath, usually the parent window. It may, therefore, be possible to put a static control, for example, beneath it and change its colour, or to paint the parent window's background beneath the groupbox. As far as I know there is no direct way of changing the background colour of a groupbox.

    For complete control over how a groupbox looks you could make it owner-drawn.

    msdn: Button .Controls
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Aug 2006
    Location
    England
    Posts
    5

    Smile

    Thanks for the reply...WM_CTLCOLORSTATIC worked first time.

    Declared at the beginning of the message handler:
    Code:
    HBRUSH hBackground = CreateSolidBrush(RGB(0, 0, 0));
    Code:
    case WM_CTLCOLORSTATIC:
    {
        HDC hdc = (HDC)wParam;
        SetBkMode(hdc, TRANSPARENT);
        SetTextColor(hdc, RGB(255, 255, 255));
        return (LONG) hBackground;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Win32 API tooltip control
    By wind_addict in forum Windows Programming
    Replies: 1
    Last Post: 05-12-2008, 07:16 AM
  2. Replies: 9
    Last Post: 02-13-2008, 02:59 PM
  3. Win32 API Tutorials?
    By c++_n00b in forum C++ Programming
    Replies: 9
    Last Post: 05-09-2002, 04:51 PM
  4. Default checking of radio button in a group box
    By juhigarg in forum Windows Programming
    Replies: 3
    Last Post: 11-08-2001, 12:25 AM
  5. Default checking of radio button in a group box
    By juhigarg in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 01:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21