Click here to Skip to main content
15,888,816 members
Articles / Desktop Programming / MFC
Article

CXPGroupBox -- XP style groupbox and window style groupbox

Rate me:
Please Sign up or sign in to vote.
4.89/5 (33 votes)
21 Apr 20041 min read 180.8K   11.5K   60   43
This class allows you to create XP style groupbox and window style groupbox.

Sample Image - xpgroupbox.jpg

Introduction

Recently, I was coding an application. I needed XP style groupbox and a window style groupbox. I did some research, but I could not find it. So I decided to write it.

How to Use it

I derived the class CXPGroupBox from CButton. It is easy to use. In the dialog resource editor, add a groupbox as usual and give an ID to the groupbox. Then use class wizard to create a member to link the groupbox. Remember, select category as "Control", and variable type as CButton.

Then go to Dialog header file and add:

#include "XPGroupBox.h" 

and also change the control type CButton to CXPGroupBox. For example, change:

CButton m_frmXPGroupBox;

to

CXPGroupBox m_frmXPGroupBox;

Then in the CPP file of the dialog class, in the OnInitDialog() function, add init code for the groupbox. In the demo file, it shows:

 m_frmWin.SetXPGroupStyle(CXPGroupBox::XPGB_WINDOW)
         .SetBackgroundColor(RGB(201, 201, 151), RGB(255, 255, 204))
         .SetFontBold(TRUE);

m_frmNormal.SetCatptionTextColor(RGB(16,140,231))
     .SetFontBold(TRUE);

m_frmWin is the new style groupbox, it looks like a window and m_frmNormal is XP style groupBox.

Enjoy it.

Class function list

virtual CXPGroupBox& SetBorderColor(COLORREF clrBorder);
virtual CXPGroupBox& SetCatptionTextColor(COLORREF clrText);
virtual CXPGroupBox& SetBackgroundColor(COLORREF clrBKClient);
virtual CXPGroupBox& SetBackgroundColor(COLORREF clrBKTilte,  
                                COLORREF clrBKClient);
virtual CXPGroupBox& SetXPGroupStyle(XPGroupBoxStyle eStyle); 

virtual CXPGroupBox& SetText(LPCTSTR lpszTitle);
virtual CXPGroupBox& SetFontBold(BOOL bBold);
virtual CXPGroupBox& SetFontName(const CString& strFont, 
                                BYTE byCharSet = ANSI_CHARSET);
virtual CXPGroupBox& SetFontUnderline(BOOL bSet);
virtual CXPGroupBox& SetFontItalic(BOOL bSet);
virtual CXPGroupBox& SetFontSize(int nSize);
virtual CXPGroupBox& SetFont(LOGFONT lf);

In the class, you can set font attributes like font name, color, size, bold, italic etc. You can change the background color of the window style groupbox and XP style groupbox as well. If you change the background color of groupbox, you will have to make the style of the controls in the groupbox transparent. Otherwise it is urgly. :)

History

  • 21 Apr 2004 - updated source and demo

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Canada Canada
I have been programming over 6 years in many languages and architectures, but the most is C++, VB, Java, ASP and now towards C#.

I am living in Toronto. I like to spend my quality time with my family.

Comments and Discussions

 
GeneralTrouble on getting message Pin
xiang_yan10-Sep-10 23:46
xiang_yan10-Sep-10 23:46 
GeneralRe: Trouble on getting message Pin
xiaoyintao11-Mar-13 19:46
xiaoyintao11-Mar-13 19:46 
GeneralHi!Hi! Pin
beikexuezi20-May-10 17:35
beikexuezi20-May-10 17:35 
Generallicense of XCPGroupBox Pin
Jan777777710-May-10 4:52
Jan777777710-May-10 4:52 
GeneralFormView repaint issue - a ghost stitching problem Pin
Astronomer14-Jul-08 14:40
Astronomer14-Jul-08 14:40 
Have you tried using the CXPGroupBox in a CFormView class? (Build standard MFC app, single document, and in last setup page select CFormView).

There is a "stitching problem" so that the groupbox appears with a ghost frame around the outside edge. Add a CXPGroupBox to the main form view window, using the toolbox in the usual fashion and changing the style from CStatic to CXPGroupBox. Make sure that ClientEdge, Modal Frame and Static Edge are all set FALSE. Then:

m_GroupBox_1.SetXPGroupStyle(CXPGroupBox::XPGB_WINDOW)
.SetCatptionTextColor(RGB(0,255,255))
.SetFontBold(TRUE)
.SetBorderColor(RGB(255,0,0))
.SetText("Hello World");

Note the SetBorderColor to RED. (Any color will do to see the problem, providing it's not near white.

The real border (appears RED) has rounded corners (fillets) and you will see that outside the real border is a rectangular frame maybe 1 pixel or so wide that appears "off-white"in color. This ghost frame most noticeable in the corners becuase the outside of the fillet area is the abberant color.

Run the app, then take another window (like "Calculator"), and wave it across the XP box. You will see that "remnants" of the Calculator window appears in the ghost frame around the XPGroupBox.

How do I get rid of this?

It works totally fine in all of the dialogs brought up inside the CFormView application; the problem is only inside the view class of a CFormView application. Why? Is it some kind of repainting problem?

Very nice little tool. Thanks Jack!
GeneralEnableWindow has no effect Pin
Joerg Hoffmann22-Jul-07 23:37
Joerg Hoffmann22-Jul-07 23:37 
QuestionLicence ??? Pin
BastianPL18-Jun-06 4:33
BastianPL18-Jun-06 4:33 
Generalproblem of refresh of Edit box Pin
Flower30313-May-06 11:15
Flower30313-May-06 11:15 
Generalproblems with window style Pin
eli1502197911-Sep-05 3:42
eli1502197911-Sep-05 3:42 
GeneralRe: problems with window style Pin
JackCa12-Sep-05 7:09
JackCa12-Sep-05 7:09 
GeneralNice Class ~~~ But Spread OCX Invisible Pin
xboxer23-Feb-05 21:35
xboxer23-Feb-05 21:35 
Generalalignment of title Pin
19-Apr-04 5:03
suss19-Apr-04 5:03 
GeneralRe: alignment of title Pin
JackCa22-Apr-04 14:37
JackCa22-Apr-04 14:37 
GeneralVery nice !!! Pin
sps-itsec4610-Feb-04 8:17
sps-itsec4610-Feb-04 8:17 
GeneralSome opaque and some invisible Pin
AAntix8-Dec-03 6:05
AAntix8-Dec-03 6:05 
GeneralRe: Some opaque and some invisible Pin
JackCa8-Dec-03 8:44
JackCa8-Dec-03 8:44 
GeneralRe: Some opaque and some invisible Pin
AAntix8-Dec-03 9:57
AAntix8-Dec-03 9:57 
GeneralRe: Some opaque and some invisible Pin
JackCa8-Dec-03 10:38
JackCa8-Dec-03 10:38 
GeneralRe: Some opaque and some invisible Pin
AAntix17-Dec-03 21:06
AAntix17-Dec-03 21:06 
GeneralControls invisible Pin
Thomasm19603-Dec-03 21:27
Thomasm19603-Dec-03 21:27 
GeneralRe: Controls invisible Pin
JackCa4-Dec-03 4:13
JackCa4-Dec-03 4:13 
GeneralRe: Controls invisible Pin
AAntix8-Dec-03 9:59
AAntix8-Dec-03 9:59 
GeneralRe: Controls invisible Pin
kbomb98711-Dec-03 8:34
kbomb98711-Dec-03 8:34 
GeneralRe: Controls invisible Pin
Thomasm196011-Dec-03 20:51
Thomasm196011-Dec-03 20:51 
GeneralRe: Controls invisible Pin
JackCa12-Dec-03 3:49
JackCa12-Dec-03 3:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.