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


Comments

  • Thanks

    Posted by Gene Sewell on 08/14/2012 12:25pm

    Thanks so much for this code. I decided I wanted this functionality - Google brought me to this link, and it just worked! Thanks for disabling everything when the checkbox is unchecked - perfect! Huzzah!

    Reply
  • Handle checkbox click

    Posted by dpreznik on 02/08/2011 11:33am

    Thank you very much for your solution, it is nice and helpful. Could you please tell me how one can handle click on the checkbox in your control? Thanks.

    Reply
  • How to create our own "font" in vc++

    Posted by rameshbabupeddapalli on 04/06/2007 07:37pm

    I have created a Combobox by dragging and drawing, i wrote a list of names the font is default. If i create the Combobox dynamically and add the list of names to combobox the font is different from the earlier (static) one.
          
            Please give me the solution to set the same font which is set by default at design (static) time.

    Reply
  • yes!

    Posted by Legacy on 06/18/2003 12:00am

    Originally posted by: hiro

    What a useful your code is!
    in gui, we want a (check/radio)box+groupbox like you showed.
    thanks :)

    Reply
  • Cool

    Posted by Legacy on 06/17/2003 12:00am

    Originally posted by: Jens Winslow

    Great idea.
    I often use this kind of enabeling / disabeling in my GUIs, and end up coding the disabeling by hand....now I wonder why I never thought to do a class to do it for me.

    Thanks for sharing this

    Jens

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds