Enhanced GroupBox Control
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:
- Include the SxGroupBox.h header file in your dialog class header file.
- 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.
- 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
//{{AFX_DATA(YourDialogClass)
...
CSxGroupBox MyGroupBox;
...
//}}AFX_DATA
...
}
[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.SetLineThickness(2);
MyGroupBox.SetLineStyle( BS_3D );
}
Downloads
Download demo project - 29 KbDownload source - 5 Kb

Comments
Background color
Posted by Legacy on 02/23/2004 12:00amOriginally posted by: Sam
Replycontrols
Posted by Legacy on 01/21/2004 12:00amOriginally posted by: yash
change the background color
ReplySmall Error, and Fix for Windows XP Themes.
Posted by Legacy on 11/26/2003 12:00amOriginally 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:
//SetWindowText(m_txtString);
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.....
Cheers!
- Jeff
ReplyGives error
Posted by Legacy on 03/26/2003 12:00amOriginally 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
Regards
ReplyFayyaz
It is what i want, and it is nice.
Posted by Legacy on 03/19/2003 12:00amOriginally posted by: zcy
Thank you!
ReplyRounded Corners
Posted by Legacy on 09/27/2002 12:00amOriginally posted by: seb
How would you round the corners of the group boxes?
Replybackground color
Posted by Legacy on 06/10/2002 12:00amOriginally posted by: todd
Very nice.
Replycan I set background color?
it's not work in Cformview
Posted by Legacy on 03/21/2002 12:00amOriginally posted by: asdmusic
it's not work in CFormView
Reply
Can i highlight it when the mouse into the group area?
Posted by Legacy on 01/31/2002 12:00amOriginally posted by: frank
Can i highlight it when the mouse into the group area?
ReplyCan I Move it ?
Posted by Legacy on 12/18/2001 12:00amOriginally posted by: Andy
How Can I Move it and resize ? Thanks
ReplyLoading, Please Wait ...