v1.74 An MFC class to provide a tree options control
Welcome to CTreeOptionsCtrl, a control which implements a tree options
control similar to the advanced tab as seen on the "Internet Options"
dialog in Internet Explorer 4 and later. In addition to boolean values, it also
allows edit boxes, combo boxes, file browser, folder browsers, color browsers, font
browsers, font name combo boxes, general opaque objects, date controls, time controls
and IP address controls to be included in the tree control, similar to the new printer
property dialogs which were introduced in Windows 2000. Included below is a snapshot
showing the demo application and what the control looks like.
The enclosed zip file contains the CTreeOptionsCtrl
source code and a simple dialog based application which exercises the class.
- You are allowed to include the source code in any product (commercial, shareware,
freeware or otherwise) when your product is released in binary form.
- You are allowed to modify the source code in any way you want except you
cannot modify the copyright details at the top of each module.
- If you want to distribute source code with your application, then you are
only allowed to distribute versions released by the author. This is to maintain
a single distribution point for the source code.
28 February 2016
- Please note that I have discontinued development of this code and it is
now considered obsolete. This is because as of Visual Studio 2008 with the MFC
Feature Pack, there is a new GUI
class which implements pretty much all the functionality of CTreeOptionsCtrl.
I have reviewed the "NewControls" MFC sample which demonstrates CMFCPropertyGridCtrl
as well as a lot of the other Feature Pack classes. With this new class, it
is relatively easily to implement:
- Hierarchical items are supported via the
- Check boxes can be implemented either via setting the value of a
property to a VT_BOOL or using a custom class derived from CMFCPropertyGridProperty.
In the NewControls sample, this corresponds most closely to the class called "CCheckBoxProp".
- You could implement radio buttons using a custom class derived from
CMFCPropertyGridProperty although you would be better advised to implement
this using the
method to add all possible values to one property instead.
- The "Your First Name" sample property in my code is supported
out of the box using the in place editor support of CMFCPropertyGridCtrl
- The "Day of the Week" and "Font Name combo" sample
properties in my code are supported via the
- If you want to link the state of one property to another such as the "Security"
sample properties then you would need to implement custom classes derived
- The "Rating" sample property in my code is supported via the
- The "File edit box" and "Folder edit box" properties
in my code are supported via the
- The "Color selector" property in my code is supported via
- The "Font Selector" property in my code is supported via the
- The "Boolean combo" property in my code is supported via setting
the value of a
property to a VT_BOOL.
- The "Date Example" and "Time Example" properties
in my code can be implemented using a custom class derived from
I was able to implement both of these using just c. 80 lines of code
- The "IP address Selector" property in my code requires a bit
more code to implement than the date or time example as I needed to modify
the CMFCPropertyGridCtrl::m_nRowHeight value to avoid clipping when the
IP address in place control was drawn. To change the m_nRowHeight value
I needed to implement a class derived from CMFCPropertyGridCtrl and override
method to increase the size of the calculated m_nRowHeight value. I also
needed to implement a class derived from
to provide access to the HasButton protected member variable. All told,
about 130 lines of code to support an IPv4 address control.
- The "Your Shoe Size" property in my code is supported via
implementing a custom class derived from
In the NewControls sample, this corresponds most closely to the class called "CCustomDlgProp"
- The "Your Shoe Size (Combo)" property in my code can be implementing
with a custom class derived from
I was able to take the class called "CTwoButtonsProp" in the "NewControls"
sample and modify it to show the standard drop down button and "..."
edit button at the same time. The drop down button then showed the combo
box values while the edit button brought up a custom editor. This was all
achieved using just c. 50 lines of code.
- The "Multi line edit control" property in my code can be implemented
using a custom class derived from
- This new built in MFC control class supports a number of additional features
such as skinning, masked edit values, embedded slider and ComboBoEx classes,
icon lists, a description bar and many other features, which now makes my implementation
V1.74 (16 March 2015)
- Updated copright details.
- Updated the code to clean compile on VC 2013
- Code no longer uses LoadLibrary without an absolute path when loading XP
Theming DLL. This avoids DLL planting security issues.
V1.73 (21 May 2012)
- Updated the code to draw disabled items in gray text. Thanks to Damir Valiulin
for this nice addition.
V1.72 (29 April 2012)
- Updated copyright details.
- Updated sample project settings to more modern defaults
- Code now compiles cleanly using Code Analysis (/analyze)
- When the parent node of a group of checkboxes is also a checkbox (e.g. the
Node "Security" in the test app) the parent is checked / unchecked
depending on the status of its children whenever a child is modified in the
GUI. This previously worked ok when you changed the checkmark of a child in
the GUI by mouse or keyboard, but it doesn't work if the change is made programmatically
(via SetCheckBox or by means of the referenced boolean variable). The code has
now been updated to handle this anomaly. Thanks to Michael Oerder for providing
this nice update.
V1.71 (20 July 2008)
- Added two missing files to the download zip file specifically the correct
sln and vcproj files. Thanks to Ingmar Koecher for reporting this issue.
- Radio buttons and check boxes now by default use a more 3d style of drawing
when XP theming is not active. You can revert back to a more flat style of drawing
these items by SetFlatStyleRadioButtons(TRUE) and SetFlatStyleCheckBoxes(TRUE)
respectively. Thanks to Ingmar Koecher for reporting this issue.
V1.70 (21 June 2008)
- Updated copyright details
- Code now compiles cleanly using Code Analysis (/analyze)
- Updated code to compile correctly using _ATL_CSTRING_EXPLICIT_CONSTRUCTORS
- The code now only supports VC 2005 or later.
- Replaced all calls to CopyMemory with memcpy
- Fixed a bug in the CTreeOptionsCtrl constructor when checking the validity
of the function pointers for XP Theming.
- Fixed a bug in the sample app's COpaqueShoeButton2::BrowseForOpaque function
V1.69 (23 December 2007)
- Updated copyright details.
- Removed VC 6 style AppWizard comments from the code.
- Optimized CTreeOptionsItemData constructor code
- Boolean member variables of CTreeOptionsItemData have now been made "bool"
instead of "BOOL".
- Fixed an issue where if you create a combo box with a style of CBS_DROPDOWN
instead of CBS_DROPDOWNLIST, then the combo box would not be properly deactivated
when it loses focus to a control outside of the TreeOptionsCtrl while the cursor
is in the combo box edit field. Thanks to Tobias Wolf for reporting this issue.
- Fixed a crash where you select a combo box item, select something in it
and then hit tab.
- Focus is now correctly transferred to a tree options button if you hit tab
on a tree options combo box.
- GetBrowseForFolderCaption, GetBrowseForFileCaption and GetFileExtensionFilter
all now by default use a string resource.
V1.68 (11 July 2006)
- Updated copyright details
- Removed unused constructor and destructor methods from some of the classes
in the sample app.
- Replaced calls to ZeroMemory with memset
- Addition of CTREEOPTIONSCTRL_EXT_CLASS macro to allow the code to be easily
added to an extension dll.
- Class now uses private messages based at WM_USER instead of WM_APP
- Optimized CTreeOptionsCtrl constructor code.
- Optimized CTreeOptionsCombo constructor code.
- Optimized CTreeOptionsDateCtrl constructor code
- Reworked CTreeOptionsDateCtrl::GetDisplayText logic
- Reworked CTreeOptionsTimeCtrl::GetDisplayText logic
- Optimized CTreeOptionsIPAddressCtrl constructor code
- Optimized CTreeOptionsEdit constructor code
- Optimized CTreeOptionsSpinCtrl constructor code
- Optimized CTreeOptionsBrowseButton constructor code
- Replaced calls to CopyMemory with memcpy
- Optimized CMultiLineEditFrameWnd constructor code
- Removed common control 6 manifest as this conflicts with VC 2005 compilation.
- Updated the code to clean compile on VC 2005.
- Updated documentation to use the same style as the web site.
10 May 2005
- Updated download to include missing manifest files for the two sample apps.
Thanks to Mark Otter for reporting this.
V1.67 (16 March 2005)
- Fix for crash when you have one of the edit controls in a IP address control
selected and you then select another item in the tree options control. Hard
to know if this is a bug in the control on in Windows itself. Either way, the
workaround fix is to ensure that the child windows of an IP Address control
are destroyed before we destroy the IP address control itself. Thanks to Steve
Hayes for reporting this problem.
V1.66 (26 January 2005)
- Both of the sample apps shipped with the class now include XP manifest files,
meaning that the full look and feel of XP Themes are shown. Thanks to Piotr
Zagawa for reporting this issue.
V1.65 (5 May 2004)
- Fixed some compiler warnings when the code is compiled using VC 7.x. Please
note that to implement these fixes, the code will now require the Platform SDK
to be installed if you compile the code on VC 6.
V1.64 (5 February 2004)
- Made HandleChildControlLosingFocus public so that it can be called from
outside the class. This is useful in the following scenario reported by RnySmile:
I noticed a bug happened only if it is used in a Property Page. I added an Edit
item, and when user leaves that item with a child control active while tabbing
away to another tab, the data of that item will lost. The solution is to ensure
HandleChildControlLosingFocus is called before a DDX_Tree... function is called
if a child control is active.
V1.63 (11 December 2003)
- Implemented the function SetUseThemes which was missing. Thanks to Marcel
Scherpenisse for reporting this problem. Also updated the sample app to enable
toggling of this setting.
- Improved the default look of radio buttons and check boxes when the control
is not XP themed. This is achieved using the virtual function GetItemIconPosition.
Thanks to Marcel Scherpenisse for reporting this issue. This update also means
that by default radio buttons and check boxes are by default draw as 16*16 icons
centred in the icon position for each item. This can of course by overridden
by derived classes.
V1.62 (18 September 2003)
- Fixed a bug when the control draws the custom draw icons when the control
does not have an image list attached. Thanks to Benoit Lariviere for reporting
- Fixed a bug where the control draws the custom draw icons in the wrong position
when the control has horizontal scroll bars. Thanks to Benoit Lariviere for
reporting this problem.
V1.61 (2 August 2003)
- Now supports multi-line edit controls as a child control.
V1.6 (31 July 2003)
- Now class does not require the use of the built in image list. This means
that now the class behaves like its parent class CTreeCtrl in that management
of the image list is entirely outside of the class and client code calls SetImageList
as per normal.
- Class now draws the radio and check box icons using custom draw.
- Class now takes advantage of XP Visual Themes when available.
- Made a number of additional functions virtual to allow more types of client
V1.56 (26 July 2003)
- Fix an issue where the child controls get drawn in the wrong place, if the
item is just on the vertical (either top or bottom) edge of the client area.
Thanks to K�gl Christoph for reporting this problem and providing the fix.
V1.55 (17 July 2003)
- Made SetRadioButton methods in CTreeOptionsCtrl virtual to allow further
V1.54 (7 June 2003)
- Fixed a bug where the date time control was not reflecting the changes when
the child control was displayed. Thanks to Tom Serface for reporting this problem.
V1.53 (14 May 2003)
- Fixed a bug where the OnSelChanged function was getting in the way when
the control was being cleared down, leading to an ASSERT. Thanks to Chen Fu
for reporting this problem.
V1.52 (6 February 2003)
- Fixed a memory leak which can occur when the control is used in a property
sheet. Thanks to David Rainey for reporting this problem.
- Fixed another memory leak in the destructor of the CTreeOptionsCtrl class
when the test app is closed.
- Did a spell check on the documentation <g>
V1.51 (15 November 2002)
- Now allows the Field Data separator i.e. ": " to be configured. Please note
that the characters you pick should be avoided in the descriptive text you display
for an item as it is used as the divider between the descriptive text and the
actual data to be edited. Thanks to K�gl Christoph for this update.
- Fixed an access violation in CTreeOptionsCtrl::OnSelchanged when there is
no selected item in the control. Thanks to K�gl Christoph for this update.
V1.50 (30 October 2002)
- Made a number of other methods const. Thanks to K�gl Christoph for reporting
V1.49 (28 October 2002)
- Fixed a bug where upon a combo losing focus it will also result in the associated
button control would also be destroyed. Thanks to K�gl Christoph for reporting
this problem. Fixed this bug should also fix an intermittent release bug which
was occurring in this area.
V1.48 (25 October 2002)
- Updated the download to include the missing files OpaqueShow.cpp/h. Thanks
to K�gl Christoph for reporting this.
- Made the class more const-correct. e.g. the Get... member functions are
now const. Thanks to K�gl Christoph for reporting this. Also updated the documentation
- Updated the documentation to refer to the "Opaque Browser" support.
V1.47 (17 October 2002)
- Added a method to add an "Opaque Browser" to the Tree options control. An
Opaque Browser is where the tree options control allows a end user specified
structure to be edited by the tree options control without it explicitly knowing
what it is editing.
V1.46 (24 September 2002)
- Updated documentation which incorrectly stated that the parent of a check
box item must be a group item as inserted with InsertGroup. Thanks to K�gl
Christoph for spotting this.
- Fixed an issue with "IMPLEMENT_DYNAMIC(CDateTimeCtrl..." not being
declared propertly. Some users reported that it worked ok, while others said
that my fix was causing link problems. The problem should be sorted out for
good now. Thanks to K�gl Christoph for reporting this.
- Renamed the SetImageListToUse function to "SetImageListResourceIDToUse".
- Provided a GetImageListResourceIDToUse function to match up with the Set
- Provided a method to allow the user item data to be changed after an item
has been created.
- Provided some documentation info how how to safely use item data in the
control. Thanks to K�gl Christoph for reporting this.
- Fixed a potential memory leak in AddComboBox if the function is invoked
twice without an explicit delete of the item first. Thanks to K�gl Christoph
for reporting this.
- Fixed some typos in the documentation. It incorectly stated that the return
type of member functions InsertGroup, InsertCheckBox, and InsertRadioButton
is BOOL when in fact it is HTREEITEM. Thanks to K�gl Christoph for reporting
- Improved the look of the disabled checked check button. Thanks to K�gl
Christoph for reporting this.
- Improved the look of the disabled radio button which is selected. Thanks
to K�gl Christoph for reporting this.
V1.45 (2 June 2002)
- Moved sample app to VC 6 to facilitate support for IP Address control and
date and time controls.
- Fixed a bug where the child controls can get orphaned when a node in the
tree control is expaned or contracted. Thanks to Lauri Ott for spotting this
- Now fully supports the CDateTimeCtrl for editing of dates and times
- Now fully supports the CIPAddressCtrl for editing of IP addresses
- Custom draw support for color browser items is now configurable via an additional
parameter of the AddColorBrowser method
V1.44 (14 February 2002)
- Now allows item data to be associated with any item added to the control.
- Fixed issue with return value from GetUserItemData.
V1.43 (13 December 2001)
- Fixed an assertion in OnClick. Thanks to "flipposwitch" for spotting
V1.42 (5 December 2001)
- Minor code tidy up following development of the author's CListOptionsCtrl
V1.41 (27 November 2001)
- Fixed a bug where the message map for OnMouseWheel was setup incorrectly.
It should have been ON_WM_MOUSEWHEEL instead of ON_MESSAGE!!!.
- Allowed passing in the hAfter item for the InsertItem calls. All parms are
defaulted as to not affect any current code.
- Made possible the use of radio button groups followed by other items (in
which case the group is considered complete).
- Added a couple of utility functions at the bottom of the cpp file. Thanks
to Mike Funduc for all these updates.
V1.4 (17 October 2001)
- Provided support for specify a color via CColorDialog.
- Controls are now created to fill the full width of the tree control.
- Provided support for specifying a font via CFontDialog.
- Provided support for specifying a font name from a combo box.
- Provided support for specifying a boolean value from a combo box.
V1.31 (27 August 2001)
- Provided a "GetUserItemData" member to provide access to the item data provided
by the class. Thanks to Colin Urquhart for this.
- Fixed a redraw problem which occured when you scrolled using an wheel enabled
mouse. Thanks to "Jef" for spotting this.
- Provided an AutoSelect option which automatically sets focus to child control
in the tree control. Thanks to "Jef" for this suggestion.
- Added full support for CBS_DROPDOWN and CBS_SIMPLE style combo boxes. Thanks
to "Jef" for this suggestion.
V1.30 (12 August 2001)
- Fixed an issue in GetComboText and GetEditText where the code was modifying
the contents of the combo/edit box when it was being read. This was because
that function is doing double duty as it is called when the child control is
about to be created in place, and you want to remove the text from the tree
control and put it in the child control. Thanks to "Jef" for spotting this.
- Made the code in SetComboText more robust. Thanks to "Jef" for this also.
- Added a DDX method for integers in a edit box. Thanks to Colin Urquhart
- Added a extra member to _TreeOptionsItemData to be used as an item data.
This allows you to avoid having to implement multiple derived classes and instead
use the item data to stash away pointers etc.
V1.26 (25 April 2001)
- Creation of the image list is now virtual. This allows customisation such
as being able to use high color bitmaps
- Added an option which determines if check box state should be changed when
you click anywhere on an item or just over the checkbox icon
- Updated copyright message
V1.25 (3 July 2000)
- Now includes support for edit boxes with accompanying spin controls.
V1.24 (30 May 2000)
- Now uses ON_NOTIFY_REFLECT_EX instead of ON_NOTIFY_REFLECT for reflected
messages. This allows derived classes to handle the message if that want to.
V1.23 (10 May 2000)
- Fixed a bug where the text was not being transferred to the control when
the in inplace combo or edit box is active and the tree control gets destroyed.
- Added support for having check box items as children of other check box
- Setting the check box state of a parent now also sets the check box state
for all child box children.
- Setting the check box state affects the check box state of the parent if
that parent is also a check box.
V1.22 (3 April 2000)
- Added support for navigation into and out of the combo boxes and edit controls
inside the control.
V1.21 (29 February 2000)
- Removed a VC 6 level 4 warning
V1.2 (8 October 1999)
- Added support for including combo boxes as well as edit boxes into the edit
- Added support for customizing the image list to use
V1.11 (5 October 1999)
- Made class more self contained by internally managing the image list.
V1.1 (21 April 1999)
- Added full support for enabling / disabling of group, check box and radio
button items (see the screen shot above).
V1.01 (20 April 1999)
- Minor Update to the bitmap which is used as the image list for the tree
V1.0 (3 April 1999)