Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group box with title as Check box

I am using Visual Studio 6.0 (VC++ with MFC) in Windows XP platform. I am trying to create a group box with the title of the group box as a check box. My intention is this: If the check box is enabled, the controls inside the group box should be enabled; or else disabled.

Is this possible to accomplish? If yes, please give me some directions.

Thanks.

like image 450
Bharani Avatar asked Jun 26 '09 08:06

Bharani


3 Answers

There are a few things you can try, depending on how true you want to stay to your idea and how much work you are prepared to put into the effort:

Simple method

Use a normal group box, and then inside this make the first item be the checkbox. This is simple to accomplish, but you lose the goal of having the checkbox as the title.

Funky drawing method 1

Use a normal group box, then in the space over where you know the title is to go, place your checkbox. You will have to perform some tricky calculation to get it to fit in nicely and draw well without flicker.

Funky drawing method 2

Use some form of superclass or subclass/subclass on the group box. You can override the WM_PAINT handler to draw in only the frame for the group box. Place a normal checkbox in the place where you know the title is to go. This should work better because you will have more control over the drawing, but it is likely to be tricky to get right. In my experience, subclassing is lower risk to implement than superclassing.

like image 61
1800 INFORMATION Avatar answered Sep 28 '22 01:09

1800 INFORMATION


Are you using the Dialog editor? If so, put down the group box. Next, on top of it, put a check box over the line of the group box. Edit the resource to set the Z order, or do it in code. You want the checkbox to be on top of the group box. Add a handler for the checkbox and enable / disable controls depending on the check box state.

like image 27
BrianK Avatar answered Sep 28 '22 01:09

BrianK


I wrote one called CGroupCheck a few years back and it's available from CodeProject: http://www.codeproject.com/KB/buttons/groupcheck123.aspx

like image 30
miliu Avatar answered Sep 28 '22 01:09

miliu