Click here to Skip to main content
14,493,767 members

Enhancements of Matthew R. Millers COptionTree

Rate this:
4.76 (15 votes)
Please Sign up or sign in to vote.
4.76 (15 votes)
26 Apr 2006CPOL
This article demonstrates an enhanced version of Matthew R. Millers Option Tree
Sample Image - screenshot1.jpg


To offer a nice setup in my private application, I was looking for a smart tree control which can embed some useful GUI controls like edit, font, colour control and more. That's exactly what's provided by Matthew Millers' COptionTree. First of all, thank you for that work Matthew. But nothing is free of charge except death (which costs your life) and so unfortunately, the version posted in September 2002 has two serious weak points. I want to ask the reader to examine the article linked above to see the features of the tree control and its internals. The two major weak points I spoke about are:

  • No drag and drop
  • Very slow and so not really usable for large lists

The Option Tree provided by this article is very close to the genuine version. It is adapted to developer studio 2003 (.NET 7.1) and comes only with *.sln and *.vcproj. So users of developer studio 6 have to create a new project and add source files. (Once they do so, they will be surprised by some compiler errors caused by changed return types of some callbacks - it should not be a problem to change that.)

Those users having Matthews' Option Tree ported to 7.1 should easily be able to use this version. Some interfaces have just been enlarged with default values.

Enhancements/Bug Fixes

  • Drag & drop within same item level
  • Faster drawing (about 20 times - a draw is performed for visible items only; frequently used resources cached) and faster creation of tree
  • Buttons to add, delete, restore default values and user definable can be integrated to item label. Once a button is pressed, a message is sent (or posted) to Receivers (pNotify of COptionTree) PreTranslateMessage with the button code and pointer of the underlying item.
  • Support of ListBoxes
  • Class COptionTreeItemEdit can be driven with an input mask (regular expression) to catch every type of input.
  • Class COptionTreeItemEdit has a method called PrepareEditItem similar to CreateEditItem. The purpose of this method is to bypass the creation of parent CEdit on building treecontrol. Once the user clicks this item, the edit control is created just in time. This improves the initial build of tree with many edit items - a type which is used most frequently presumably.

    BOOL COptionTreeItemEdit::PrepareEditItem(const CString& sWindowText,
                                              DWORD dwOptions,
                                              DWORD dwAddStyle,
                                              const CString& inputmask)    

    NOTE: Due to performance reasons, it is strongly recommended to call Tree.LockUpdate() before filling the tree and Tree.UnlockUpdate() once the work is done. Matthew forgot to point this out.

  • Positioning of colour popup on multi screens corrected
  • An item changed message is sent only if an item value has really been changed
  • No trouble on scrolling by thumbtrack in large lists

Demo Description

The demo demonstrates the original and new features and performance enhancements. A test button can be used to insert 3000 items in one step and a microsecond based clock measures and displays the elapsed time.

Using the Code

The demo project contains all the source and project files. I put the tree files into a library project, so it can statically be linked to any project. Below this tree project, the demo version is located in directory test. The test project links the tree lib statically. This is casually an example of using the tree lib. Simply load COptionTreeDemoDl.sln located in libtree/test, build and run it. Comments, bug reports and suggestions are welcome.

Bug Fixes

  • After scrolling or expanding, listbox and multiline edittext sometimes stayed visible
  • No item changed notification was sent for date/time control if user edited values with keyboard
  • Some COptionTreeItem derivates stayed visible on scrolling
  • Column sizing failed if COptionTree::_bAutoSizeColumn == false
  • COptionTree::EnsureVisible failed

New Features

  • Option 'Autosize column' added
  • User definable height for listbox
  • User definable offset for attribute text (call COptionTree::SetAttributeOffset)
  • Item Search by Label (/Attribute-Text: not implemented for all COptionTreeItem derivates)

    COptionTreeItem * COptionTree::FindItem(const CString& Text,
                                            const DWORD flag=OT_FI_LABEL,
                                            COptionTreeItem * pOffset=NULL)


  • Focus killed on scrolling for COptionTreeItemIPAddress, COptionTreeItemEdit, COptionTreeItemEditButton, COptionTreeItemDate
  • More proper drawing of Expand Box
  • COptionTreeCheckButton derived from COptionTreeItem
  • COptionTreeRadioButton derived from COptionTreeItem (to avoid multiple pointer instances to COptionTree)


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


About the Author

Cornelius Eichhorst
Web Developer
Germany Germany
No Biography provided

Comments and Discussions

GeneralBug in VS2008 void COptionTreeColorPopUp::Initialize() Pin
Member 11754912-Apr-10 1:41
MemberMember 11754912-Apr-10 1:41 
GeneralRe: Bug in VS2008 void COptionTreeColorPopUp::Initialize() Pin
gpidat28-Jun-10 2:45
Membergpidat28-Jun-10 2:45 
QuestionHow can I create multi column, such as three or more(like list has this tree function) Pin
iacxin14-Jun-09 20:42
Memberiacxin14-Jun-09 20:42 
GeneralBoundschecker reports errors Pin
Member 4873983-Mar-09 19:26
MemberMember 4873983-Mar-09 19:26 
QuestionVisual Studio 2005 Pin
vahid_m_200824-Aug-08 8:19
Membervahid_m_200824-Aug-08 8:19 
GeneralRegExp class doesn't work well in unicode Pin
ugly beast27-Dec-07 13:39
Memberugly beast27-Dec-07 13:39 
GeneralRe: RegExp class doesn't work well in unicode [modified] Pin
wheregone5-Apr-11 21:15
Memberwheregone5-Apr-11 21:15 
QuestionCOptionTreeItemEditButton Pin
iarspider21-Nov-07 0:45
Memberiarspider21-Nov-07 0:45 
QuestionHow do you use this tree from the DLL? [modified] Pin
Tydia-kun6-Nov-07 10:52
MemberTydia-kun6-Nov-07 10:52 
GeneralCtlColor CMaskEdit Pin
sanity_CZ14-Aug-07 21:43
Membersanity_CZ14-Aug-07 21:43 
QuestionHelp! [modified] Pin
Lin Cheng15-Jul-07 22:36
MemberLin Cheng15-Jul-07 22:36 
AnswerRe: Help! Pin
sanity_CZ14-Aug-07 21:48
Membersanity_CZ14-Aug-07 21:48 
QuestionRe: Help! Pin
Lin Cheng18-Aug-07 6:10
MemberLin Cheng18-Aug-07 6:10 
GeneralCPreciseTimer class: Notice states "The use of the strictly prohibited." Pin
domKing2-Jul-07 14:30
MemberdomKing2-Jul-07 14:30 
GeneralRe: CPreciseTimer class: Notice states "The use of the strictly prohibited." Pin
Cornelius Eichhorst2-Jul-07 14:49
MemberCornelius Eichhorst2-Jul-07 14:49 
GeneralFYI: Corrected problems in libtree with Unicode build Pin
domKing2-Jul-07 14:26
MemberdomKing2-Jul-07 14:26 
GeneralCBS_SIMPLE [modified] Pin
matrosso22-Apr-07 23:43
Membermatrosso22-Apr-07 23:43 
QuestionExellent work, I will use it in my daily life.:) Pin
Z.L. Dong13-Dec-06 16:55
MemberZ.L. Dong13-Dec-06 16:55 
QuestionBeep? Pin
iberg14-Sep-06 4:27
Memberiberg14-Sep-06 4:27 
AnswerRe: Beep? Pin
Cornelius Eichhorst2-Jul-07 14:51
MemberCornelius Eichhorst2-Jul-07 14:51 
GeneralHiding an item or subtree Pin
crazyjeb8018-Aug-06 3:53
Membercrazyjeb8018-Aug-06 3:53 
GeneralRe: Hiding an item or subtree Pin
crazyjeb805-Sep-06 7:52
Membercrazyjeb805-Sep-06 7:52 
GeneralRe: Hiding an item or subtree Pin
Cornelius Eichhorst9-Sep-06 3:35
MemberCornelius Eichhorst9-Sep-06 3:35 
Generalbuttons and windows 98 Pin
georgewmr6-Aug-06 19:32
Membergeorgewmr6-Aug-06 19:32 
GeneralRe: buttons and windows 98 Pin
Cornelius Eichhorst9-Sep-06 3:27
MemberCornelius Eichhorst9-Sep-06 3:27 

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.

Posted 27 Mar 2006


59 bookmarked