CPropTree class implements a tree control that is similar to the property
view seen in Visual Studio .Net. The source project compiles to a DLL so you can easily incorporate
it into your project. You can check my web page for more information
on the control.
The control has two window areas:
- Tree Control
- Descriptive area
The tree control section functions just a like a normal tree control with an addition of a
splitter bar separating the tree item properties. Tree item properties are inherited from
CPropTreeItem class. These items can be edit controls, static text, dropdown
combo list, or any type of control you wish to create. Items on the root level of the tree
control do not have editable properties. They are used as section headers.
Tree items can contain checkboxes. By default properties that are editable (non-readonly), are displayed in
bold lettering. Read only or non-editable items are displayed in a normal font.
The descriptive area displays the selected item's text and any informational text. This section can
be displayed or hidden by calling
To use the control, create an instance of the class in your dialog or view class header. In
OnCreate() initialize the control:
// PTS_NOTIFY - CPropTree will send notification messages to the parent window
dwStyle = WS_CHILD|WS_VISIBLE|PTS_NOTIFY;
// Init the control's size to cover the entire client area
// Create CPropTree control
m_Tree.Create(dwStyle, rc, this, IDC_PROPERTYTREE);
To add items to the control, dynamically create objects inherited by the
class and call the
pItem1 = m_Tree.InsertItem(new CPropTreeItem());
pItem1->SetInfoText(_T("This is a root level item"));
pItem2 = m_Tree.InsertItem(new CPropTreeItemEdit(), pItem1);
pItem2->SetInfoText(_T("This is a child item of Properties, with an edit control"));
pItem2->SetItemValue((LPARAM)_T("This is some default text for the edit control"));
The control uses
WM_NOTIFY notification messages to signal events. Add a
message handler to the parent window to process notifications. The control supports
most of the common NM_ codes with addition of the following
PTN_INSERTITEM when an item is inserted
PTN_DELETEITEM when an item is about to be deleted
PTN_DELETEALLITEMS when a call is made to delete all items
PTN_ITEMCHANGED when an item's property has been modified
PTN_SELCHANGE when the current selection changed
PTN_ITEMEXPANDING when an item is about to expand or close
PTN_COLUMNCLICK when the mouse clicks on the splitter bar
PTN_PROPCLICK when the mouse clicks on an item's property area
PTN_CHECKCLICK when the mouse clicks on an item's checkbox
notification messages returns the
structure. You can use this structure along with the
method to determine the tree item that sent an event.
ON_NOTIFY(PTN_ITEMCHANGED, IDC_PROPERTYTREE, OnItemChanged)
void CMyDialog::OnItemChanged(NMHDR* pNotifyStruct, LRESULT* plResult)
LPNMPROPTREE pNMPropTree = (LPNMPROPTREE)pNotifyStruct;
// retrieve pItem's changed data
*plResult = 0;
Custom Property Items
The library already has some default derived
CPropTreeItem classes ready
to use. Such as an edit control
CPropTreeItemColor, dropdown combobox
CPropTreeItemStatic. To create your own custom property items:
- Create your own class inherited by
CPropTreeItem. This class usually will have
multiple inheritance depending on what type of item you want to create.
class CMyCustomEditPropItem : public CEdit, public CPropTreeItem
class CMyCustomComboBoxPropItem : public CComboBox, public CPropTreeItem
- Override the
CPropTreeItem virtual methods to implement your property item.
- Dynamically create an instance of your class and insert it into a
The methods most often overriden from
CPropTreeItem::OnActivate(). Called when the property area is clicked by the mouse
or the enter key has been pressed on the selected item. The
OnActivate() method is where you
show the property item's window if it has one (such as an edit control or a popup menu).
CPropTreeItem::OnCommit(). Called when data has been commited. In this method you would extract
the changed data and hide the property's item's window.
OnCommit() gets called when
is called. A derived
CPropTreeItem class would call
CommitChanges() during a loss of the input
focus or if the "Enter" key is press as in a edit control.
the property item needs to be displayed. Drawing is done directly on the display context of the PropTree control.