COXOptionTreeCtrl
Copyright © The Code Project 1997-2005, All Rights Reserved

COXOptionTreeControl is a CTreeCtrl derived class that allows you to use check boxes and radio buttons as tree items. Tree control functionality allows you to organize them in groups, which provides a compact way of displaying and navigating through a big number of options that can be represented using check box or radio button.

In most cases options should be organized in some logical way. We associate a tree control brunch with any of such group of options and call them "control groups". Please note that the functionality of the tree control allows you to use multiple level of dependency between groups and subgroups. In order to add new control group in the tree control you have to call the following function:
AddControlGroup();

Using this function you may create any control groups. This function returns a handle to the tree item that was created to display the control group title. You can use this value to add check boxes, radio buttons or other control groups.
In order to add new check box item in the tree you have to use the following function:
AddCheckBox();
In order to add new radio button item in the tree you have to use the following function:
AddRadioButton();

Note that both of this functions require you to specify a unique ID of new option control. This way any check box or radio button can be uniquely identified throughout the option tree control. In order to retrieve the ID of an option control that is specified by its handle to the tree item you can call:
GetItemFromID();
And if you need to get the handle of a tree item which corresponds to the given ID you can call:
GetIDFromItem();

Using first three function you can easily populate option tree control. You also can use all standard CTreeCtrl functions that are used in order to populate a tree control with items. 

We would like to emphasize one specific rule that applies to the way COXOptionTreeCtrl must be used which different from the standard approach. You must not explicitly change the image list associated with tree. We use our own internally in order to display check box and radio button images. But what if you want to display some images for control group items? AddControlGroup() function allows you to specify the image indexes for normal and selected state but these indexes must be returned by the following function which add new image to the internal image list:
AddImage();
Using this function you can add as many images as you want. 

Although it is not supposed to be modified outside but we still decided to provide a direct access to the internal image list. You may retrieve a pointer to it using 
the following function:
GetImageList();
One of the possible use of the image list would be replacing of the images we use to display check box and radio button. At this moment the following images are predefined:

Index	Image	
0	unchecked box	
1	checked box	
2	unselected radio button	
3	selected radio button	
            
After the control is populated and displayed a user can expand and collapse control groups and change state of option items left clicking mouse or pressing down SPACE key.
 
Whenever the state of an option item is changed the following notification will be send in form of WM_NOTIFY message:
OTN_OPTIONCHANGED
If you handle the notification you have to cast NMHDR* object to NMOPTIONTREE* object.
NMOPTIONTREE structure provides info about the item, which state has been changed, the old state and the new state of the item. NMOPTIONTREE structure is declared as following:

typedef struct _tagNMOPTIONTREE
{
    // standard header
    NMHDR hdr;
    // handle to the tree item (check box or radio button, which state 
    // has been changed)
    HTREEITEM hItem;
    // item ID
    UINT uItemID;
    // old item state: OTITEM_UNCHECKED or OTITEM_CHECKED
    int nOldCheck;
    // new item state: OTITEM_UNCHECKED or OTITEM_CHECKED
    int nNewCheck;
} NMOPTIONTREE, * LPNMOPTIONTREE;

The state of any option item can be programmatically retrieved and changed using the following set of functions:

SetCheck();
GetCheck();
GetCheckedRadioButton();
IsCheckBox();
IsRadioButton();

And, finally, we provide the functionality to save to and load from registry option settings. Use these two functions to do that:
SaveState();
LoadState();