Click here to Skip to main content
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() PinmemberMember 11754912-Apr-10 2:41 
GeneralRe: Bug in VS2008 void COptionTreeColorPopUp::Initialize() Pinmembergpidat28-Jun-10 3:45 
I've had same problem: work with OS>= Vista but not with OS<=XP
The problem is caused by SPI_GETNONCLIENTMETRICS, structure has changed
see: http://msdn.microsoft.com/en-us/library/ms724506%28VS.85%29.aspx
 
To make it work correctly :
void COptionTree::InitGlobalResources()
{
// Declare variables
CWindowDC dc(NULL);
LOGFONT lfFont;
BOOL bUseSystemFont;
 
// Delete global resources
DeleteGlobalResources();

/////////////////////////
//fix
////Get system parameter information
// cmInfo.cbSize = sizeof(cmInfo);
// ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(cmInfo), &cmInfo, 0);
NONCLIENTMETRICS cmInfo;
UINT cbSize = sizeof(NONCLIENTMETRICS);
// if we're targeted for Vista, the NONCLIENTMETRICS struct
// will be the wrong size for XP, so adjust if necessary.
#if(WINVER >= 0x0600)
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof( versionInfo );
GetVersionEx( &versionInfo );
// If we are running under XP, deduct the size of the
// iPaddedBorderWidth member added in Vista.
if ( versionInfo.dwMajorVersion < 6 )
{
cbSize -= sizeof(int);
}
#endif
cmInfo.cbSize = cbSize;
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS, cmInfo.cbSize, &cmInfo, 0));
//fix
QuestionHow can I create multi column, such as three or more(like list has this tree function) Pinmemberiacxin14-Jun-09 21:42 
GeneralBoundschecker reports errors PinmemberMember 4873983-Mar-09 20:26 
QuestionVisual Studio 2005 Pinmembervahid_m_200824-Aug-08 9:19 
GeneralRegExp class doesn't work well in unicode Pinmemberugly beast27-Dec-07 14:39 
GeneralRe: RegExp class doesn't work well in unicode [modified] Pinmemberwheregone5-Apr-11 22:15 
QuestionCOptionTreeItemEditButton Pinmemberiarspider21-Nov-07 1:45 
QuestionHow do you use this tree from the DLL? [modified] PinmemberTydia-kun6-Nov-07 11:52 
GeneralCtlColor CMaskEdit Pinmembersanity_CZ14-Aug-07 22:43 
QuestionHelp! [modified] PinmemberLin Cheng15-Jul-07 23:36 
AnswerRe: Help! Pinmembersanity_CZ14-Aug-07 22:48 
QuestionRe: Help! PinmemberLin Cheng18-Aug-07 7:10 
GeneralCPreciseTimer class: Notice states "The use of the software...is strictly prohibited." PinmemberdomKing2-Jul-07 15:30 
GeneralRe: CPreciseTimer class: Notice states "The use of the software...is strictly prohibited." PinmemberCornelius Eichhorst2-Jul-07 15:49 
GeneralFYI: Corrected problems in libtree with Unicode build PinmemberdomKing2-Jul-07 15:26 
GeneralCBS_SIMPLE [modified] Pinmembermatrosso23-Apr-07 0:43 
QuestionExellent work, I will use it in my daily life.:) PinmemberLeon Dong13-Dec-06 17:55 
QuestionBeep? Pinmemberiberg14-Sep-06 5:27 
AnswerRe: Beep? PinmemberCornelius Eichhorst2-Jul-07 15:51 
GeneralHiding an item or subtree Pinmembercrazyjeb8018-Aug-06 4:53 
GeneralRe: Hiding an item or subtree Pinmembercrazyjeb805-Sep-06 8:52 
GeneralRe: Hiding an item or subtree PinmemberCornelius Eichhorst9-Sep-06 4:35 
Generalbuttons and windows 98 Pinmembergeorgewmr6-Aug-06 20:32 
GeneralRe: buttons and windows 98 PinmemberCornelius Eichhorst9-Sep-06 4:27 

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.141216.1 | Last Updated 26 Apr 2006
Article Copyright 2006 by Cornelius Eichhorst
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid