Click here to Skip to main content
15,881,882 members
Articles / Desktop Programming / MFC
Article

Simplest Checkable Groupbox Class

Rate me:
Please Sign up or sign in to vote.
4.31/5 (13 votes)
4 Dec 20032 min read 120.6K   2.7K   23   27
Lots of time we want to enable/disable a set of controls in our dialog. Checkable Groupbox can even assemble a radio-style group!

Image 1

Introduction

Lots of time we want to disable a set of controls in our dialog. Group box is a good control to categorize a few controls together, but unfortunately it cannot enable/disable its controls. I extended CButton class and made it very simple to accomplish this 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 idea of other talented programmers.

How to use it

  1. Draw a group box in resource editor as usual. In resource editor, change the style property of group box to icon or bitmap, this prevents Overlapped text when tab is pressed!

    Styles Page

    You can also enable tab key navigation by enabling Tab Stop in group box resource like following

    Gerenal Page

  2. Add a member variable for this added group box, but choose CCheckableGroupBox as control type.
  3. In OnInitDialog(), call m_yourVariable.SetTitleStyle(BS_AUTOCHECKBOX); to change normal title to a check box, or use BS_AUTORADIOBUTTON for radio box.
  4. you want a group of group box toggle by radio box title, just create more Checkable group box as you already did, and call SetGroupID to give them a group!
  5. In updated version of this control, I support DDX_Check, which means now you can use UpdateData() to update and save the state of check box in an standard MFC fashion.

Because the check/radio box is created when SetTitleStyle() is called, no variable update is applicable before that point. If you want to update the status from a member variable, please call UpdateData(FALSE) after that. I know it's not perfect but it's not that bad anyway.

History

  • Updated (21/11/03) - Supports windows WM_ENABLE message. Now you can call EnableWindow() to disable the whole group!
  • Updated (24/11/03) - Suppot DDX_Check for variable exchange. Please refer to demo project for details. Tab support by enable tab stop style in resource.
  • Updated (02/12/03) - Send BN_CLICKED Message to parent dialog while title box is clicked. This is crucial if you use this control along with my Data Driven UI Behaviour Pattern.
  • Updated (03/12/03) - Support embedded group boxes (Groupbox inside another), no level or number limitations!

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
Software Developer (Senior) www.wonga.com
Ireland Ireland
I have over 13 Years IT industry experience as Principle/Senior Programmer. I am experienced in .NET/J2EE system design and detailed implementation. I master UML modelling and OO design methodology with a strong C#/C++/Java coding background. I have been in working/managing a distributed project using Agile/Waterfall approach. My business knowledge includes Telecommunication, Financial Investment/Trading, and Banking.

Comments and Discussions

 
Generalchoose CCheckableGroupBox as control type. Pin
Member 463143222-Apr-08 3:11
Member 463143222-Apr-08 3:11 
GeneralXP Style & Radion Button Type Pin
JimmyO28-Nov-07 2:45
JimmyO28-Nov-07 2:45 
Question? SS_NOTIFY Pin
Synetech14-Sep-06 15:54
Synetech14-Sep-06 15:54 
Anyone know how to get a CCheckableGroupBox to send notifications to the parent? I need to add a tooltip to one but it does not have the SS_NOTIFY style and I can't figure out how/where to set it.


--
Synetech

GeneralSetting text colour (XP style) Pin
huw216-Aug-06 4:22
huw216-Aug-06 4:22 
GeneralRe: Setting text colour (XP style) Pin
Dieter Hammer16-Apr-09 4:58
Dieter Hammer16-Apr-09 4:58 
Questionhow to make gropbox control dynamically. Pin
baldha rakesh9-Mar-06 19:28
baldha rakesh9-Mar-06 19:28 
QuestionOverlapped text when tab is pressed Pin
sguay17-Jan-06 7:44
sguay17-Jan-06 7:44 
General! Toggle Visibility Instead of Enabled Pin
Synetech5-Nov-04 14:25
Synetech5-Nov-04 14:25 
General! This class is more useful than you think Pin
Synetech21-Oct-04 11:00
Synetech21-Oct-04 11:00 
General! 3 state checkbox Pin
Synetech26-Jul-04 13:54
Synetech26-Jul-04 13:54 
GeneralUpdate List Pin
Ziming12-Jun-03 22:36
Ziming12-Jun-03 22:36 
GeneralSomething to look into. Pin
WREY12-Jun-03 1:27
WREY12-Jun-03 1:27 
GeneralRe: Something to look into. Pin
Ziming12-Jun-03 1:30
Ziming12-Jun-03 1:30 
GeneralRe: Something to look into. Pin
WREY12-Jun-03 1:55
WREY12-Jun-03 1:55 
GeneralRe: Something to look into. Pin
Igor Okulist12-Jun-03 2:38
Igor Okulist12-Jun-03 2:38 
GeneralRe: Something to look into. Pin
Ziming12-Jun-03 2:41
Ziming12-Jun-03 2:41 
GeneralRe: Something to look into. Pin
WREY12-Jun-03 3:15
WREY12-Jun-03 3:15 
GeneralI believe I found the reason!! Pin
WREY12-Jun-03 3:29
WREY12-Jun-03 3:29 
GeneralRe: I believe I found the reason!! Pin
Troy Russell26-May-09 9:47
Troy Russell26-May-09 9:47 
GeneralTimeStamp Utilities Pin
WREY15-Jun-03 4:52
WREY15-Jun-03 4:52 
GeneralRe: Something to look into. Pin
Synetech21-Oct-04 10:46
Synetech21-Oct-04 10:46 
GeneralUpdated Pin
Ziming12-Jun-03 2:39
Ziming12-Jun-03 2:39 
GeneralRe: Updated Pin
Martin Cook12-Jun-03 2:42
professionalMartin Cook12-Jun-03 2:42 
GeneralRe: Updated Pin
Martin Cook12-Jun-03 7:00
professionalMartin Cook12-Jun-03 7:00 
GeneralRe: Updated Pin
WREY12-Jun-03 10:48
WREY12-Jun-03 10:48 

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.