Click here to Skip to main content
15,881,248 members
Articles / Desktop Programming / MFC
Article

Enhancements of Matthew R. Millers COptionTree

Rate me:
Please Sign up or sign in to vote.
4.76/5 (15 votes)
26 Apr 2006CPOL3 min read 119.7K   2.6K   58   41
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.

    C++
    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)

    C++
    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)


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralBug in VS2008 void COptionTreeColorPopUp::Initialize() Pin
Member 11754912-Apr-10 1:41
Member 11754912-Apr-10 1:41 
GeneralRe: Bug in VS2008 void COptionTreeColorPopUp::Initialize() Pin
gpidat28-Jun-10 2:45
gpidat28-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
iacxin14-Jun-09 20:42 
GeneralBoundschecker reports errors Pin
Member 4873983-Mar-09 19:26
Member 4873983-Mar-09 19:26 
QuestionVisual Studio 2005 Pin
vahid_m_200824-Aug-08 8:19
vahid_m_200824-Aug-08 8:19 
GeneralRegExp class doesn't work well in unicode Pin
ugly beast27-Dec-07 13:39
ugly beast27-Dec-07 13:39 
GeneralRe: RegExp class doesn't work well in unicode [modified] Pin
wheregone5-Apr-11 21:15
wheregone5-Apr-11 21:15 
QuestionCOptionTreeItemEditButton Pin
iarspider21-Nov-07 0:45
iarspider21-Nov-07 0:45 
QuestionHow do you use this tree from the DLL? [modified] Pin
Tydia-kun6-Nov-07 10:52
Tydia-kun6-Nov-07 10: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 21:43
sanity_CZ14-Aug-07 21:43 
QuestionHelp! [modified] Pin
Lin Cheng15-Jul-07 22:36
Lin Cheng15-Jul-07 22:36 
AnswerRe: Help! Pin
sanity_CZ14-Aug-07 21:48
sanity_CZ14-Aug-07 21:48 
QuestionRe: Help! Pin
Lin Cheng18-Aug-07 6:10
Lin Cheng18-Aug-07 6:10 
GeneralCPreciseTimer class: Notice states "The use of the software...is strictly prohibited." Pin
domKing2-Jul-07 14:30
domKing2-Jul-07 14:30 
GeneralRe: CPreciseTimer class: Notice states "The use of the software...is strictly prohibited." Pin
CppChinaski2-Jul-07 14:49
CppChinaski2-Jul-07 14:49 
GeneralFYI: Corrected problems in libtree with Unicode build Pin
domKing2-Jul-07 14:26
domKing2-Jul-07 14:26 
GeneralCBS_SIMPLE [modified] Pin
matrosso22-Apr-07 23:43
matrosso22-Apr-07 23:43 
QuestionExellent work, I will use it in my daily life.:) Pin
Z.L. Dong13-Dec-06 16:55
Z.L. Dong13-Dec-06 16:55 
QuestionBeep? Pin
User 58261914-Sep-06 4:27
User 58261914-Sep-06 4:27 
AnswerRe: Beep? Pin
CppChinaski2-Jul-07 14:51
CppChinaski2-Jul-07 14:51 
GeneralHiding an item or subtree Pin
crazyjeb8018-Aug-06 3:53
crazyjeb8018-Aug-06 3:53 
GeneralRe: Hiding an item or subtree Pin
crazyjeb805-Sep-06 7:52
crazyjeb805-Sep-06 7:52 
GeneralRe: Hiding an item or subtree Pin
CppChinaski9-Sep-06 3:35
CppChinaski9-Sep-06 3:35 
Generalbuttons and windows 98 Pin
georgewmr6-Aug-06 19:32
georgewmr6-Aug-06 19:32 
GeneralRe: buttons and windows 98 Pin
CppChinaski9-Sep-06 3:27
CppChinaski9-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.