This tree control is a multl-select tree control. This allows the user to select items via rubber band selection. Even though
there are a lot of multi-select tree controls published and floating in the web, I tried to make one that was simple to use.
Using the code
The user can simply use it like the
CTreeCtrl can be replaced with the
This allows some methods to change the style of the tree control like
AddLineAtRoot(), etc. It has a callback facility which calls the function
when looping through the items. To loop through the items, a special function is provided, namely
IterateItems(). This function takes the callback function as one
of the parameters. The user can specify the start and end item for looping.
void CCustomTreeCtrl::IterateItems( ScanCallBackFunc func,
HTREEITEM hStart ,
if( !hStart )
hStart = GetRootItem();
ScanItems( func,hStart,hEnd,pInfo );
void CCustomTreeCtrl::ScanItems( ScanCallBackFunc func,
HTREEITEM hStart ,
while( hStart )
lInfo.pTree = this;
lInfo.hItem = hStart;
lInfo.pParent = GetParent();
lInfo.param = pInfo;
GetItemRect( hStart,&rc,FALSE );
func( &lInfo );
if( hStart == hEnd )
HTREEITEM hChild = NULL;
if( ItemHasChildren( hStart ) )
hChild = GetChildItem( hStart );
hStart = GetNextSiblingItem( hStart );
Points of Interest
I have learnt a lot of new things while customizing the tree control, like how to create the drag image if there is multiple selection.
I have taken some sample code from CodeProject articles to accomplish this. But I think I have made the multiple selection quite easy and I have provided lots of comments which
will be very helpful to understand the code.
This is the first version of the code. Based on the user feedback and bug reports, I'll update the code and try to deliver the best. Please feel free to send your feedback.
I'm working as Senior software Engineer since 7 years and interested in MFC and COM programming.