Virtual Developer Workshop: Containerized Development with Docker

Environment: VC6, Win98/NT4/2K

If you want to customize the look of the standard GroupBox control then the SxGroupBox class can be most helpful for you. It provides functions for customizing the font, color, and style. Most of the work is done in the OnPaint message handler. You can easily change the OnPaint function yourself to add other effects such as rounded corners or other line styles or box styles.

You can follow these steps to use the class:
  1. Include the SxGroupBox.h header file in your dialog class header file.
  2. Use class wizard to create a control data member of type CSxGroupBox.  If the CSxGroupBox type does not appear in the class wizard control type combobox then just choose CButton and then manually edit your dialog class header file and replace the CButton with CSxGroupBox.  
  3. Add whatever commands you want to your dialog class cpp file to customize the appearance of the GroupBox.

A sample application is included that shows most of the features of SxGroupBox.

The following code snippet shows how to call some of the functions.

[In File YourDialogClass.h]

#include "SxGroupBox.h"

class YourDialogClass : public CDialog

// Dialog Data
  CSxGroupBox	MyGroupBox;


[In File YourDialogClass.cpp]

void YourDialogClass::YourFunction()
  // create font
  CSxLogFont Arial12b(120,FW_BOLD,false,"Arial");
  // set the custom font, text color, and alignment
  MyGroupBox.SetFont( &Arial12b );
  MyGroupBox.SetTextColor( RGB(100,0,0) );
  MyGroupBox.SetTextAlign( BS_CENTER );
  // set the custom line colors, thickness, and style
  MyGroupBox.SetBoxColors( RGB(100,0,0), RGB(255,100,100) );
  MyGroupBox.SetLineStyle( BS_3D );


Download demo project - 29 Kb
Download source - 5 Kb


  • Background color

    Posted by Legacy on 02/23/2004 08:00am

    Originally posted by: Sam

    Mr Toby Norris, thank a lot for your code. It is very gut and I have saved a lot of Time.

    To change the background follow this:


    // Brush for bacground
    CBrush m_Brush;


    m_Brush.CreateSolidBrush( RGB(214,220,236) );

    //OnCtlColor return a handle to the brush that is to be //used for painting the control background.
    HBRUSH CTeileInfo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
    if ( pWnd->m_hWnd == m_YourControl.m_hWnd) {
    pDC->SetTextColor( RGB_BLACK );
    pDC->SetBkMode( TRANSPARENT);
    return HBRUSH( m_Brush);
    return HBRUSH( m_Brush);

    Good luck!!

  • controls

    Posted by Legacy on 01/21/2004 08:00am

    Originally posted by: yash

    change the background color

  • Small Error, and Fix for Windows XP Themes.

    Posted by Legacy on 11/26/2003 08:00am

    Originally posted by: Jeffrey Donovan

    Nice class! I noticed however that when I compiled this with a program set to use XP themes, if there were other controls that take keyboard focus in the same frame, then when you would TAB through the controls the Title Text would blur as it was written twice in different spots. After some debugging, I determined what was happening is that for some reason, XP is still itself trying to repaint the title (when XP themes are enabled) and as such was overwriting your custom text title.

    The solution is:

    1) Do not use any text on the Group Box when desiging it in the resource editor, and use the SetText function to set it's title.

    2) In the source file, SxGroupBox.cpp, in the function SetText(), remark out the line to set the window text, as in:


    Your custom string (m_txtString) is still set and thus still drawn in your custom paint function, but now XP does not have a title to draw and overwrite your text. This provides the same functionality on all platforms. Hope that might help some.....


    - Jeff

  • Gives error

    Posted by Legacy on 03/26/2003 08:00am

    Originally posted by: Fayyaz

    Does not works in my project. Upon compile gives following error

    error C2039: 'DrawText' : is not a member of 'CPaintDC'

    looks like strange as DrawText is member of CDC class which is the base class of CPainDC?

    any solution to this problem


  • It is what i want, and it is nice.

    Posted by Legacy on 03/19/2003 08:00am

    Originally posted by: zcy

    Thank you!

  • Rounded Corners

    Posted by Legacy on 09/27/2002 07:00am

    Originally posted by: seb

    How would you round the corners of the group boxes?

  • background color

    Posted by Legacy on 06/10/2002 07:00am

    Originally posted by: todd

    Very nice.
    can I set background color?

  • it's not work in Cformview

    Posted by Legacy on 03/21/2002 08:00am

    Originally posted by: asdmusic

    it's not work in CFormView

  • Can i highlight it when the mouse into the group area?

    Posted by Legacy on 01/31/2002 08:00am

    Originally posted by: frank

    Can i highlight it when the mouse into the group area?

  • Can I Move it ?

    Posted by Legacy on 12/18/2001 08:00am

    Originally posted by: Andy

    How Can I Move it and resize ? Thanks

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date