Click here to Skip to main content
15,888,980 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

 
GeneralRe: Controls invisible Pin
Dandy Cheung14-Jan-04 15:11
Dandy Cheung14-Jan-04 15:11 
GeneralRe: Controls invisible Pin
Dandy Cheung14-Jan-04 15:16
Dandy Cheung14-Jan-04 15:16 
GeneralRe: Controls invisible Pin
David Pritchard9-Aug-05 1:07
David Pritchard9-Aug-05 1:07 
GeneralRe: Controls invisible Pin
jack.pan11-Apr-07 2:37
jack.pan11-Apr-07 2:37 
GeneralRe: Controls invisible Pin
JasonAw27-May-07 20:01
JasonAw27-May-07 20:01 
GeneralRe: Controls invisible Pin
basti27116-Sep-07 3:23
basti27116-Sep-07 3:23 
GeneralRe: Controls invisible Pin
basti27116-Sep-07 3:35
basti27116-Sep-07 3:35 
GeneralDrawing bug Pin
Dominik Reichl3-Dec-03 9:11
Dominik Reichl3-Dec-03 9:11 
GeneralRe: Drawing bug Pin
miguelviana3-Dec-03 10:11
miguelviana3-Dec-03 10:11 
GeneralRe: Drawing bug Pin
JackCa3-Dec-03 10:24
JackCa3-Dec-03 10:24 
Generaledit control into group not visible Pin
miguelviana3-Dec-03 8:52
miguelviana3-Dec-03 8:52 
GeneralRe: edit control into group not visible Pin
miguelviana3-Dec-03 9:08
miguelviana3-Dec-03 9:08 
GeneralRe: edit control into group not visible Pin
JackCa3-Dec-03 9:08
JackCa3-Dec-03 9:08 
Generaljust a question... Pin
l a u r e n3-Dec-03 7:29
l a u r e n3-Dec-03 7:29 
GeneralRe: just a question... Pin
armentage3-Dec-03 7:55
armentage3-Dec-03 7:55 
GeneralRe: just a question... Pin
JackCa3-Dec-03 8:20
JackCa3-Dec-03 8:20 
GeneralRe: just a question... Pin
l a u r e n3-Dec-03 8:59
l a u r e n3-Dec-03 8:59 
GeneralRe: just a question... Pin
armentage3-Dec-03 9:04
armentage3-Dec-03 9:04 

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.