Simplest Checkable Groupbox

Environment: MFC

Brief—Simplest Checkable Groupbox Control

Often, we want to disable a set of controls in our dialog. A group box is a good control to categorise a few controls together, but unfortunately it cannot enable/disable its controls. I extended the CButton class and made it very simple to accomplish and it is encapsulated into one class.

So, you can change the title of a group box into a check box or radio button (then you need more group boxes, of course). I must confess I borrowed some ideas of other talented programmers.

How to Use It

  1. Draw a group box in the resource editor as usual.
  2. Add a member variable for this added group box, but choose CCheckableGroupBox as the control type.
  3. In OnInitDialog(), call m_yourVariable.SetTitleStyle(BS_AUTOCHECKBOX); to change the normal title to a check box, or use BS_AUTORADIOBUTTON for a radio box.
  4. If you want a group of group boxes toggled by radio box title, just create more Checkable group boxes as you already did, and call SetGroupID to give them a group!
  5. And that’s ALL!

Ziming Wang
ziming.wang@spectel.com

Downloads


Download demo project – 35 Kb


Download source code – 3 Kb

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read