views:

1429

answers:

3

Hi,

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.

+1  A: 

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.

1800 INFORMATION
Method 1 worked for me!!
Bharani
I've used Funky Drawing Method 1 several times. Make sure the Text for the group box is blank and keep an eye on the tab order or the controls won't draw correctly.
NascarEd
+1  A: 

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.

BrianK
A: 

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

miliu