CXPGroupBox -- XP style groupbox and window style groupbox






4.89/5 (30 votes)
Dec 3, 2003
1 min read

184715

11534
This class allows you to create XP style groupbox and window style groupbox.
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