Click here to Skip to main content
11,437,978 members (51,897 online)
Click here to Skip to main content

Enhancements of Matthew R. Millers COptionTree

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

Introduction

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)

Changes

  • 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)

License

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

Share

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 2:41
memberMember 11754912-Apr-10 2:41 
GeneralRe: Bug in VS2008 void COptionTreeColorPopUp::Initialize() Pin
gpidat28-Jun-10 3:45
membergpidat28-Jun-10 3:45 
QuestionHow can I create multi column, such as three or more(like list has this tree function) Pin
iacxin14-Jun-09 21:42
memberiacxin14-Jun-09 21:42 
GeneralBoundschecker reports errors Pin
Member 4873983-Mar-09 20:26
memberMember 4873983-Mar-09 20:26 
QuestionVisual Studio 2005 Pin
vahid_m_200824-Aug-08 9:19
membervahid_m_200824-Aug-08 9:19 
GeneralRegExp class doesn't work well in unicode Pin
ugly beast27-Dec-07 14:39
memberugly beast27-Dec-07 14:39 
GeneralRe: RegExp class doesn't work well in unicode [modified] Pin
wheregone5-Apr-11 22:15
memberwheregone5-Apr-11 22:15 
QuestionCOptionTreeItemEditButton Pin
iarspider21-Nov-07 1:45
memberiarspider21-Nov-07 1:45 
QuestionHow do you use this tree from the DLL? [modified] Pin
Tydia-kun6-Nov-07 11:52
memberTydia-kun6-Nov-07 11:52 
Nothing is exported from the DLL so I can't use it... The demo project can use it, but I just don't understand HOW it can use it when the library clearly isn't exporting anything,
Anyone knows?


-- modified at 17:20 Tuesday 6th November, 2007
GeneralCtlColor CMaskEdit Pin
sanity_CZ14-Aug-07 22:43
membersanity_CZ14-Aug-07 22:43 
QuestionHelp! [modified] Pin
Lin Cheng15-Jul-07 23:36
memberLin Cheng15-Jul-07 23:36 
AnswerRe: Help! Pin
sanity_CZ14-Aug-07 22:48
membersanity_CZ14-Aug-07 22:48 
QuestionRe: Help! Pin
Lin Cheng18-Aug-07 7:10
memberLin Cheng18-Aug-07 7:10 
GeneralCPreciseTimer class: Notice states "The use of the software...is strictly prohibited." Pin
domKing2-Jul-07 15:30
memberdomKing2-Jul-07 15:30 
GeneralRe: CPreciseTimer class: Notice states "The use of the software...is strictly prohibited." Pin
Cornelius Eichhorst2-Jul-07 15:49
memberCornelius Eichhorst2-Jul-07 15:49 
GeneralFYI: Corrected problems in libtree with Unicode build Pin
domKing2-Jul-07 15:26
memberdomKing2-Jul-07 15:26 
GeneralCBS_SIMPLE [modified] Pin
matrosso23-Apr-07 0:43
membermatrosso23-Apr-07 0:43 
QuestionExellent work, I will use it in my daily life.:) Pin
Leon Dong13-Dec-06 17:55
memberLeon Dong13-Dec-06 17:55 
QuestionBeep? Pin
iberg14-Sep-06 5:27
memberiberg14-Sep-06 5:27 
AnswerRe: Beep? Pin
Cornelius Eichhorst2-Jul-07 15:51
memberCornelius Eichhorst2-Jul-07 15:51 
GeneralHiding an item or subtree Pin
crazyjeb8018-Aug-06 4:53
membercrazyjeb8018-Aug-06 4:53 
GeneralRe: Hiding an item or subtree Pin
crazyjeb805-Sep-06 8:52
membercrazyjeb805-Sep-06 8:52 
GeneralRe: Hiding an item or subtree Pin
Cornelius Eichhorst9-Sep-06 4:35
memberCornelius Eichhorst9-Sep-06 4:35 
Generalbuttons and windows 98 Pin
georgewmr6-Aug-06 20:32
membergeorgewmr6-Aug-06 20:32 
GeneralRe: buttons and windows 98 Pin
Cornelius Eichhorst9-Sep-06 4:27
memberCornelius Eichhorst9-Sep-06 4:27 
Questionhash_map? Pin
crazyjeb8025-Jul-06 5:27
membercrazyjeb8025-Jul-06 5:27 
AnswerRe: hash_map? Pin
Patrik Müller13-Aug-06 21:47
memberPatrik Müller13-Aug-06 21:47 
General How to add it to CDialogBar or CFormView child? Help! Pin
georgewmr13-May-06 5:36
membergeorgewmr13-May-06 5:36 
GeneralRe: How to add it to CDialogBar or CFormView child? Help! Pin
Cornelius Eichhorst14-May-06 11:57
memberCornelius Eichhorst14-May-06 11:57 
GeneralRe: How to add it to CDialogBar or CFormView child? Help! Pin
georgewmr15-May-06 8:07
membergeorgewmr15-May-06 8:07 
GeneralTwo problems... Pin
Patrik Müller25-Apr-06 22:34
memberPatrik Müller25-Apr-06 22:34 
GeneralApply to latest posts Pin
Cornelius Eichhorst26-Apr-06 5:47
memberCornelius Eichhorst26-Apr-06 5:47 
GeneralRe: Apply to latest posts Pin
Patrik Müller27-Apr-06 3:33
memberPatrik Müller27-Apr-06 3:33 
GeneralRe: Apply to latest posts Pin
DarrenGl25-Aug-06 1:21
memberDarrenGl25-Aug-06 1:21 
GeneralRe: Apply to latest posts Pin
Patrik Müller29-Aug-06 21:39
memberPatrik Müller29-Aug-06 21:39 
QuestionEnsureVisible doesn't work anymore? Pin
KHDev4u25-Apr-06 21:10
memberKHDev4u25-Apr-06 21:10 
GeneralA bug Pin
ionaran23-Apr-06 16:06
memberionaran23-Apr-06 16:06 
GeneralThanks for the drawing speed update... Pin
KHDev4u14-Apr-06 14:49
memberKHDev4u14-Apr-06 14:49 
GeneralNice but... Pin
Stan Alex6-Apr-06 12:22
memberStan Alex6-Apr-06 12:22 
GeneralRe: Nice but... Pin
Cornelius Eichhorst8-Apr-06 10:51
memberCornelius Eichhorst8-Apr-06 10:51 
GeneralRe: Nice but... Pin
Stan Alex8-Apr-06 12:15
memberStan Alex8-Apr-06 12:15 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150506.1 | Last Updated 26 Apr 2006
Article Copyright 2006 by Cornelius Eichhorst
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid