Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

CGroup - A Powerful Group Control

0.00/5 (No votes)
22 Aug 2001 1  
A CButton-derived class that will give groups more powerful functionality.

CGroup - example

CGroup - exemple

Introduction

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(); }

Credits

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

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