Click here to Skip to main content
15,177,535 members
Articles / Desktop Programming / WTL
Posted 16 Mar 2006


75 bookmarked

TreeCtrl - A WTL Tree Control with Windows Vista Style Item Selection

Rate me:
Please Sign up or sign in to vote.
5.00/5 (23 votes)
9 Apr 2006CPOL
A WTL tree control that supports Windows Vista style selection and multiple selection

Image 1


After quite a few requests, I thought I'd post this tree control that uses a similar selection drawing style to the list control I posted here: ListCtrl - A WTL list control with Windows Vista style item selection. For an added bonus, I've also included support for multiple-selection.

How to Use CTreeCtrl

Simply use the tree control as you would the normal CTreeViewCtrl, however there are a couple of functions required to activate and retrieve multiple selections:

void ShowThemed( 
    BOOL bShowThemed = TRUE


Draw item selection themed.


  • bShowThemed - TRUE = Draw themed selection; FALSE = Classic mode
void SetMultipleSelect( 
       BOOL bMultipleSelect


Turns on/off multiple selection.


  • bMultipleSelect - TRUE = Turn on multiple select
void GetSelectedItems( 
    CSimpleArray < HTREEITEM >& aSelectedItems


Retrieves a list of selected tree items.


  • aSelectedItems - Reference to an array of HTREEITEM


Any comments or suggestions are welcome.


  • 16th March, 2006: 1.0
    • First release
  • 20th March, 2006: 1.1
    • Small bug fix for VS2005
  • 5th April, 2006: 1.2
    • Corrected problems with multiple select and checkboxes - many thanks to Phil C.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

United Kingdom United Kingdom
Alan has been developing applications for a very long time (~10 years), but he's not bitter about this at all. My main area of expertise is C++. He lives in Sweden with his beautiful wife, daughter and son and enjoys climbing mountains and kayaking in his spare time (which isn't much).

Comments and Discussions

Questionwhy i can not download the sample code? Pin
asdf112212-Nov-12 23:47
Memberasdf112212-Nov-12 23:47 
QuestionSetWindowTheme Pin
Xenophōne31-Aug-12 1:11
professionalXenophōne31-Aug-12 1:11 
Question不能用啊??? Pin
zhangjingfei21-Jan-10 1:52
Memberzhangjingfei21-Jan-10 1:52 
AnswerRe: 不能用啊??? Pin
Xenophōne31-Aug-12 1:01
professionalXenophōne31-Aug-12 1:01 
GeneralOnLButtonUp is not called correctly Pin
JinXu24-Apr-08 6:15
MemberJinXu24-Apr-08 6:15 
Generalfatal error RC1015: cannot open include file 'atlres.h'. Pin
aditya raut18-Sep-07 16:58
Memberaditya raut18-Sep-07 16:58 
GeneralRe: fatal error RC1015: cannot open include file 'atlres.h'. Pin
asight18-Oct-13 0:43
Memberasight18-Oct-13 0:43 
QuestionVC6 Pin
toddma26-Jun-07 10:54
Membertoddma26-Jun-07 10:54 
AnswerRe: VC6 Pin
toddma26-Jun-07 10:56
Membertoddma26-Jun-07 10:56 
GeneralMake the tree items editable Pin
shaohao5-Aug-06 6:52
Membershaohao5-Aug-06 6:52 
GeneralFixes for keeping selection when clicking expand and collapse and setting background color Pin
J Chris Davies19-Apr-06 8:44
MemberJ Chris Davies19-Apr-06 8:44 
QuestionIt's very nice , but have MFC version ? Pin
XiaoQing Li18-Apr-06 0:36
MemberXiaoQing Li18-Apr-06 0:36 
GeneralDisplay problem Pin
Black.Stone13-Apr-06 21:35
MemberBlack.Stone13-Apr-06 21:35 
GeneralLooks great, but ... Pin
_oti3-Apr-06 15:34
Member_oti3-Apr-06 15:34 
GeneralRe: Looks great, but ... Pin
AlanW9-Apr-06 23:43
MemberAlanW9-Apr-06 23:43 
Generalgreat work but I find a bug! Pin
lihezhao17-Mar-06 6:11
Memberlihezhao17-Mar-06 6:11 
GeneralRe: great work but I find a bug! Pin
AlanW17-Mar-06 6:32
MemberAlanW17-Mar-06 6:32 
GeneralATLApp Error Pin
Sreekanth Muralidharan17-Mar-06 3:48
MemberSreekanth Muralidharan17-Mar-06 3:48 
GeneralRe: ATLApp Error Pin
Urquan Master17-Mar-06 7:45
MemberUrquan Master17-Mar-06 7:45 
GeneralRe: ATLApp Error Pin
Urquan Master17-Mar-06 8:13
MemberUrquan Master17-Mar-06 8:13 
GeneralRe: ATLApp Error Pin
AlanW17-Mar-06 10:26
MemberAlanW17-Mar-06 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.