CCheckStatic






4.94/5 (16 votes)
Mar 13, 2001

112355

1843
A Static derived class which provides a check box to enable/disable items inside it
Introduction
Recently at work, I was asked for help trying to put a button on top of a static box, and decided instead to write a class that encapsulated the behaviour desired. I promptly did nothing about it, until last night my crying son left me no chances of sleep and the idea came back to me in my semi-exausted stupor.
Basically the idea is this: if you drag out a static
box to bound some controls, you can go into the header
file and change the variable type to CCheckStatic
, and
automatically you will have a check box in the top left
corner of the static, and checking/unchecking the box
will enable/disable any control inside the box that has a
TAB stop ( well, almost, read the screen of the demo for
some known issues ). When I say automatically, don't
forget you need to call the Init() method in your
OnInitDialog in order to set it all up.
If you want to get a bit more fancy, you can simply add ID's of items you want to control, and only those items will be effected. This allows you to both exclude items within the box and also include items outside it. It also means you don't need a TAB stop on each item in the box. So it's probably the best way to go, but it requires some more setting up and I always like the idea of a class being able to take care of itself, as well as being flexible, so both behaviours are presented for your gourmet selection...
Here is a list of the methods exposed by CCheckStatic
.
It's hopefully pretty self explanatory.
//void Init(); // Though shalt always call this before using my class. //int AddItem(int ID); // Adds a control to the custom list //void ClearItems(); // Empties the custom list //void SetCheck(BOOL check); // Sets the check state and toggles dialog items
That's about all I have to say. Feel free to send suggestions/flames/FatBrain gift vouchers to the above address as you see fit.