Click here to Skip to main content
5,788,212 members and growing! (19,039 online)
Email Password   helpLost your password?
Desktop Development » Miscellaneous » General     Intermediate

Simplest Checkable Groupbox Class

By Ziming

Lots of time we want to enable/disable a set of controls in our dialog. Checkable Groupbox can even assemble a radio-style group!
VC6, VC7, VC7.1, C++Windows, Win2K, WinXP, Win2003, MFC, VS6, Visual Studio, Dev

Posted: 11 Jun 2003
Updated: 4 Dec 2003
Views: 58,659
Bookmarked: 17 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
12 votes for this Article.
Popularity: 4.11 Rating: 3.81 out of 5
1 vote, 8.3%
1
1 vote, 8.3%
2
3 votes, 25.0%
3
1 vote, 8.3%
4
6 votes, 50.0%
5

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

About the Author

Ziming


I worked in Chinese Bank and Telecom for years before I moved to Dublin. Many languages played, system shifted, but the most is C++, Java and C#.

Occupation: Web Developer
Location: United States United States

Other popular Miscellaneous articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 25 (Total in Forum: 25) (Refresh)FirstPrevNext
Generalchoose CCheckableGroupBox as control type.memberMember 46314324:11 22 Apr '08  
GeneralXP Style & Radion Button TypememberJimmyO3:45 28 Nov '07  
Question? SS_NOTIFYmemberSynetech16:54 14 Sep '06  
GeneralSetting text colour (XP style)memberhuw25:22 16 Aug '06  
Generalhow to make gropbox control dynamically.memberBankey Khandelwal20:28 9 Mar '06  
QuestionOverlapped text when tab is pressedmembersguay8:44 17 Jan '06  
General! Toggle Visibility Instead of EnabledmemberSynetech15:25 5 Nov '04  
General! This class is more useful than you thinkmemberSynetech12:00 21 Oct '04  
General! 3 state checkboxmemberSynetech14:54 26 Jul '04  
GeneralUpdate ListmemberZiming23:36 12 Jun '03  
GeneralSomething to look into.memberWREY2:27 12 Jun '03  
GeneralRe: Something to look into.memberZiming2:30 12 Jun '03  
GeneralRe: Something to look into.memberWREY2:55 12 Jun '03  
GeneralRe: Something to look into.memberokigan3:38 12 Jun '03  
GeneralRe: Something to look into.memberZiming3:41 12 Jun '03  
GeneralRe: Something to look into.memberWREY4:15 12 Jun '03  
GeneralI believe I found the reason!!memberWREY4:29 12 Jun '03  
GeneralTimeStamp UtilitiesmemberWREY5:52 15 Jun '03  
GeneralRe: Something to look into.memberSynetech11:46 21 Oct '04  
GeneralUpdatedmemberZiming3:39 12 Jun '03  
GeneralRe: UpdatedmemberMartin C Cook3:42 12 Jun '03  
GeneralRe: UpdatedmemberMartin C Cook8:00 12 Jun '03  
GeneralRe: UpdatedmemberWREY11:48 12 Jun '03  
GeneralRe: UpdatedmemberWREY18:34 12 Jun '03  
GeneralRe: UpdatedmemberZiming22:50 12 Jun '03  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 4 Dec 2003
Editor: Nishant Sivakumar
Copyright 2003 by Ziming
Everything else Copyright © CodeProject, 1999-2009
Web12 | Advertise on the Code Project