Click here to Skip to main content
15,166,587 members
Articles / Desktop Programming / MFC
Posted 21 Aug 2001


48 bookmarked

CGroup - A Powerful Group Control

Rate me:
Please Sign up or sign in to vote.
3.33/5 (3 votes)
22 Aug 20011 min read
A CButton-derived class that will give groups more powerful functionality.

CGroup - example

CGroup - exemple


CGroup is a CButton-derived class. The group becomes a roll-up control with many features and options. Any controls confined within the group area will hide when the group is "closed" and show when it's "open". If more than one CGroup object share the same parent window, they will attract themselves vertically (this option can be disabled). Furthermore, many aspects of the control are fully customizable (see the Methods section for more information).

Using CGroup

  1. Add the files Group.h and Group.cpp to your project, using Project / Add To Project / Files...
  2. Create a Group object in your dialog.
  3. Give it a unique ID (e.g. IDC_GROUP1).
  4. Put some controls in it (checkboxes, listbox, editbox, etc.). [Note: the controls must be COMPLETELY contained within the group].
  5. Create a member variable for the group you've created. (If the type CGroup is not available, leave CButton).
  6. If member variable type is different from CGroup, go to the header file for the dialog where you created the group and replace the CButton in front of your variable name by CGroup.
  7. Don't forget to add #include "group.h" in the same file.
  8. You can now use any methods associated with the CGroup object you've created (see the demo project for more information). Group can be contained within other groups (Rev. - 23 August 2001).

Methods (public)

//return a pointer to the CGroup object...
CGroup* GetGroupCtrl() { return this; }

// Change the titlebar color
void SetBarColor(COLORREF color) { m_barColor = color; Invalidate(); }

// Change the title text color
void SetTextColor(COLORREF color) { m_textColor = color; Invalidate(); }

// Tells the group whether it attracts other groups or not
// Attraction is vertical and descending.
// Any CGroup placed under the current
// CGroup will be, if they didn't disable their attraction, attracted.
void SetAttract(bool toggle = false) { m_attract = toggle; Invalidate(); }

// Set whether the group can fold or not...
// As a result, the button will hide/show
void SetFold(bool toggle = true);

// Add a bitmap to the title bar and assign a color mask
// If the bitmap is bigger than the title bar, you can
// choose to resize the bar automatically.
void SetBitmap(UINT bmpID,COLORREF mask = RGB(0,0,0),
                               bool resizeBar = false);

// Toggle to tell whether the group can be attracted
void SetAttraction(bool toggle = true) 
  { m_IsAttracted = toggle; Invalidate(); }

// Set text font using either a LOGFONT or variables
void SetTextFont (LOGFONT lf);
void SetTextFont (CString face,int size = 12, 
  bool bold = true,bool italic = false,bool underline = false);

//Set the title bar height
void SetBarHeight(int h);

// Set whether the group will change its height or not when attracted
// (ie the bottom of the group area will remain the same, hence increasing 
// or decreasing the height of the group as other groups fold above it)
void SetLastGroup(bool toggle = false) {m_last = toggle; Invalidate(); }

//Set whether the last control (lowest) in the group 
//will have its height modified by attraction
void SetLastCtrl(bool toggle = false) 
  {m_extendLastCtrl = toggle; Invalidate(); }

//Toggle the display of the frame for the group
void DrawGroupBorder(bool toggle = true) 
  { m_borders = toggle; Invalidate(); }

//toggle the display the frame for the title bar
void DrawBarBorder(bool toggle = true) 
  { m_barBorders = toggle; Invalidate(); }


The transparent bitmap class and functions have been written by Paul Reynolds.


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


About the Author

David Msika
United States United States
No Biography provided

Comments and Discussions

GeneralGood, but... Pin
LupinTaiwan28-May-06 19:26
MemberLupinTaiwan28-May-06 19:26 
Questionhow to use functional keys only for controling player(sound) Pin
iipc10-Jul-04 0:34
Memberiipc10-Jul-04 0:34 
GeneralReally good! Pin
Anonymous15-May-03 8:29
MemberAnonymous15-May-03 8:29 
Generalgood Pin
23-Aug-01 16:10
suss23-Aug-01 16:10 
GeneralGood stuff, bad idea Pin
23-Aug-01 7:45
suss23-Aug-01 7:45 
GeneralRe: Good stuff, bad idea Pin
23-Aug-01 8:31
suss23-Aug-01 8:31 
GeneralRe: Good stuff, bad idea Pin
Stefan Pedersen23-Aug-01 16:27
MemberStefan Pedersen23-Aug-01 16:27 
GeneralRe: Good stuff, bad idea Pin
David Msika23-Aug-01 18:10
MemberDavid Msika23-Aug-01 18:10 
GeneralRe: Good stuff, bad idea Pin
[James Pullicino]24-Aug-01 0:21
Member[James Pullicino]24-Aug-01 0:21 
GeneralRe: Good stuff, bad idea Pin
Michael A. Barnhart27-Aug-01 15:17
MemberMichael A. Barnhart27-Aug-01 15:17 

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.