What's New with 2.0
The long awaited 2.0 version is here. Good news is you get new features, new options, new items, and new bugs. Bad news is, a lot has changed so you may need to change around your current code to implement the new version.
(Thanks to Tom and Irfan for there fixes for bugs that haunted me at night when the lights are
off. They deserve their names in bold.)
Contents
Features
Below are some of the many features that COptionTree
has.
- Static controls.
- Edit controls.
- Combo box controls.
- Check box controls.
- Radio controls.
- Spinner controls.
- Color controls.
- Date and time controls.
- Image controls.
- Font controls.
- Files and folders controls.
- IP Address controls..
- Hyperlink controls.
- Automatic column resize limit.
- Easy customized options for different GUI style.
- Easy customized options for each control item.
- And more...
Usage
You have two options for using COptionTree
, you can use it in static form or
as a DLL.
Add The following files to your project:
/COptionTreeDemo/COptionTree DLL/DLL.h
/COptionTreeDemo/COptionTree DLL
Creating the control:
#include "OptionTree.h"
CRect rcClient;
DWORD dwStyle, dwOptions;
GetClientRect(rcClient);
dwStyle = WS_CHILD | WS_VISIBLE;
dwOptions = OT_OPTIONS_SHADEEXPANDCOLUMN | OT_OPTIONS_SHADEROOTITEMS;
if (m_otTree.Create(dwStyle, rcClient, this, dwOptions,
IDC_OPTIONSTREE_OPTIONS) == FALSE)
{
TRACE0("Failed to create options control.\r\n");
return FALSE;
}
Available Tree Options
OT_OPTIONS_SHOWINFOWINDOW
OT_OPTIONS_NOTIFY
OT_OPTIONS_DEFINFOTEXTNOSEL
OT_OPTIONS_SHADEEXPANDCOLUMN
OT_OPTIONS_SHADEROOTITEMS
Validating Tree Items
OT_ITEM_STATIC
OT_ITEM_CHECKBOX
OT_ITEM_COLOR
OT_ITEM_COMBOBOX
OT_ITEM_DATE
OT_ITEM_EDIT
OT_ITEM_IMAGE
OT_ITEM_RADIO
OT_ITEM_SPINNER
OT_ITEM_FONT
OT_ITEM_FILE
OT_ITEM_IPADDRESS
API Reference
This is a list of the most common used functions of COptionTree's classes. There many more functions than this, but these give the average user enough to use the control.
COptionTree
BOOL COptionTree::Create(DWORD dwStyle, RECT rcRect, CWnd* pParentWnd,
DWORD dwTreeOptions, UINT nID)
void COptionTree::DeleteAllItems()
void COptionTree::DeleteItem(COptionTreeItem *otiItem)
void COptionTree::DisableInput(BOOL bDisable)
COptionTreeItem * COptionTree::InsertItem(COptionTreeItem *otiItem,
COptionTreeItem *otiParent)
COptionTreeItem
COptionTreeItem
is a class used to handle items in a tree. Each options/preference is a different item. Depending on what type of item control is used, these functions are
acquired by all control types.
void COptionTreeItem::SetLabelText(CString strLabel)
CString COptionTreeItem::GetLabelText()
void COptionTreeItem::SetInfoText(CString strText)
CString COptionTreeItem::GetInfoText()
void COptionTreeItem::ReadOnly(BOOL bReadOnly)
BOOL COptionTreeItem::IsReadOnly()
void COptionTreeItem::OnSelect()
BOOL COptionTreeItem::IsReadOnly()
COptionTreeItemStatic
COptionTreeItemStatic
is a simple static control. The following are custom functions used to set the edit the static text.
void COptionTreeItemStatic::SetStaticText(CString strStaticText)
CString COptionTreeItemStatic::GetStaticText()
COptionTreeItemEdit
COptionTreeItemEdit
handles like a regular edit control. You can also use all of the standard functions that you would normally use with a CEdit control.
BOOL COptionTreeItemEdit::CreateEditItem(BOOL bMultiline, BOOL bPassword,
BOOL bNumerical, DWORD dwAddStyle)
BOOL COptionTreeItemEdit::GetMultiline()
BOOL COptionTreeItemEdit::GetNumerical()
BOOL COptionTreeItemEdit::GetPassword()
void COptionTreeItemEdit::SetMultiline(BOOL bMultiline)
void COptionTreeItemEdit::SetEditDouble(double dValue)
void COptionTreeItemEdit::SetEditDword(DWORD dwValue)
void COptionTreeItemEdit::SetEditFloat(float fValue)
void COptionTreeItemEdit::SetEditInt(int nValue)
void COptionTreeItemEdit::SetEditLong(long lValue)
BOOL COptionTreeItemEdit::GetEditDouble(double &dReturn)
BOOL COptionTreeItemEdit::GetEditDword(DWORD &dwReturn)
BOOL COptionTreeItemEdit::GetEditFloat(float &fReturn)
BOOL COptionTreeItemEdit::GetEditInt(int &nReturn)
BOOL COptionTreeItemEdit::GetEditLong(long &lReturn)
COptionTreeItemComboBox
COptionTreeItemComboBox
handles like a regular combo box control. You can also use all of the standard functions that you would normally use with a CComboBox control.
BOOL COptionTreeItemComboBox::CreateComboItem(DWORD dwAddStyle)
void COptionTreeItemComboBox::SetDropDownHeight(long lHeight)
COptionTreeItemCheckBox
COptionTreeItemCheckBox
is a check box control.
BOOL COptionTreeItemCheckBox::CreateCheckBoxItem(BOOL bChecked, BOOL bShowCheck,
BOOL bShowText)
BOOL COptionTreeCheckButton::GetCheck()
void COptionTreeCheckButton::SetCheckText(CString strChecked, CString strUnChecked)
COptionTreeItemRadio
COptionTreeItemRadio
is a radio box control.
BOOL COptionTreeItemRadio::CreateRadioItem()
void COptionTreeItemRadio::InsertNewRadio(CString strText, BOOL bChecked)
int COptionTreeItemRadio::GetCheckedRadio()
COptionTreeItemSpinner
COptionTreeItemSpinner
is a spinner control that allows users to select numerical values..
BOOL COptionTreeItemSpinner::CreateSpinnerItem(BOOL bWrapAround, BOOL bUserEdit,
double dValue, double dRangeBottom, double dRangeTop)
void COptionTreeSpinnerButton::SetEditDouble(double dValue)
void COptionTreeSpinnerButton::SetEditDword(DWORD dwValue)
void COptionTreeSpinnerButton::SetEditFloat(float fValue)
void COptionTreeSpinnerButton::SetEditInt(int nValue)
void COptionTreeSpinnerButton::SetEditLong(long lValue)
BOOL COptionTreeSpinnerButton::GetEditDouble(double &dReturn)
BOOL COptionTreeSpinnerButton::GetEditDword(DWORD &dwReturn)
BOOL COptionTreeSpinnerButton::GetEditFloat(float &fReturn)
BOOL COptionTreeSpinnerButton::GetEditInt(int &nReturn)
BOOL COptionTreeSpinnerButton::GetEditLong(long &lReturn)
void COptionTreeSpinnerButton::GetRange(double &dBottom, double &dTop)
void COptionTreeSpinnerButton::SetRange(double dBottom, double dTop)
COptionTreeItemColor
COptionTreeItemColor
is a control to allow the user to select or set a custom color.
BOOL COptionTreeItemColor::CreateColorItem(COLORREF rcColor,
COLORREF rcAutomatic, BOOL bShowHex,
BOOL bLiveUpdate)
COLORREF COptionTreeItemColor::GetColor()
void COptionTreeItemColor::SetColor(COLORREF rcColor)
void COptionTreeItemColor::SetShowHex(BOOL bShow)
void COptionTreeItemColor::SetLiveUpdate(BOOL bLive)
COptionTreeItemDate
COptionTreeItemDate
is a control to allow the user to select or set a date or time. You can also use all of the standard functions that you would normally use with a CDateTimeCtrl control.
BOOL COptionTreeItemDate::CreateDateItem(CString strFormat, DWORD dwDateStyle)
COptionTreeItemImage
COptionTreeItemIcon
is a control to allow the user to select an icon.
BOOL COptionTreeItemImage::CreateImageItem(DWORD dwOptions, CSize sImageSizes,
int nNumberColumns)
int COptionTreeItemImage::GetSelection()
void COptionTreeItemImage::AddBitmap(CString strBitmap, COLORREF crMask, CString strText)
void COptionTreeItemImage::AddBitmap(UINT uBitmap, COLORREF crMask, CString strText)
void COptionTreeItemImage::AddBitmap(CBitmap &bBitmap, COLORREF crMask, CString strText)
void COptionTreeItemImage::AddIcon(UINT uIcon, CString strText)
void COptionTreeItemImage::AddIcon(HICON hIcon, CString strText)
COptionTreeItemFont
COptionTreeItemFont
is a control to allow the user to select an font.
BOOL COptionTreeItemFont::CreateFontItem(LOGFONT lfFont, COLORREF crFontColor,
LOGFONT lfDefaultFont, COLORREF crDefaultFontColor, DWORD dwOptions)
BOOL COptionTreeItemFont::CreateFontItem(LOGFONT lfFont, COLORREF crFontColor,
DWORD dwOptions)
BOOL COptionTreeItemFont::CreateFontItem(CHARFORMAT cfFont, COLORREF crFontColor,
CHARFORMAT cfDefaultFont, COLORREF crDefaultFontColor, DWORD dwOptions)
BOOL COptionTreeItemFont::CreateFontItem(CHARFORMAT cfFont, COLORREF crFontColor,
DWORD dwOptions)
void COptionTreeItemIcon::SetCurFont(CHARFORMAT cfFont)
void COptionTreeItemIcon::SetCurFont(LOGFONT lf)
void COptionTreeItemIcon::SetDefaultFont(CHARFORMAT cfFont)
void COptionTreeItemIcon::SetDefaultFont(LOGFONT lf)
void COptionTreeItemIcon::SetTextColor(COLORREF crColor)
void COptionTreeItemIcon::SetDefaultTextColor(COLORREF crColor)
void COptionTreeItemIcon::SetApplyWindow(CWnd *pWnd)
COptionTreeItemFile
COptionTreeItemFile
is a control to allow the user to select a file or folder.
BOOL COptionTreeItemFile::CreateFileItem(CString strFile, CString strDefExt,
CString strFilter, DWORD dwOptions,
DWORD dwDlgFlags)
CString COptionTreeItemFile::GetSelectedFolder()
CString COptionTreeItemFile::GetFileDrive()
CString COptionTreeItemFile::GetFileDir()
CString COptionTreeItemFile::GetFileExt()
CString COptionTreeItemFile::GetFileTitle()
CString COptionTreeItemFile::GetFileName()
CString COptionTreeItemFile::GetPathName()
CString COptionTreeItemFile::GetNextPathName(POSITION& pos)
POSITION GetStartPosition()
COptionTreeItemIPAddress
COptionTreeItemIPAddress
is a control to allow the user to select a IP Address.
BOOL COptionTreeItemIPAddress::CreateIPAddressItem(DWORD dwAddStyle)
COptionTreeItemHyperLink
COptionTreeItemHyperLink
is a control to allow the user to click on a hyperlink.
BOOL COptionTreeItemIPAddress::CreateHyperlinkItem(DWORD dwOptions,
CString strLink, COLORREF crLink, COLORREF crHover = NULL,
COLORREF crVisited = NULL)
Notifications
You can have your application be notified of certain events that happen in the tree control. Below is an
example of how to be notified when an event happens, and all the notifications you can have.
YourDialog.h
ON_NOTIFY(OT_NOTIFY_ITEMCHANGED, IDC_OPTIONSTREE_OPTIONS, OnTreeItemChanged)
END_MESSAGE_MAP()
YourDialog.cpp
void CYourDialog::OnTreeItemChanged(NMHDR* pNotifyStruct, LRESULT* plResult)
{
LPNMOPTIONTREE pNMOptionTree = (LPNMOPTIONTREE)pNotifyStruct;
if (pNMOptionTree->pItem != NULL)
{
return 1;
}
*plResult = 0;
}
Available Notifications
OT_NOTIFY_INSERTITEM
OT_NOTIFY_DELETEITEM
OT_NOTIFY_DELETEALLITEMS
OT_NOTIFY_ITEMCHANGED
OT_NOTIFY_ITEMBUTTONCLICK
OT_NOTIFY_SELCHANGE
OT_NOTIFY_ITEMEXPANDING
OT_NOTIFY_COLUMNCLICK
OT_NOTIFY_PROPCLICK
Creating Custom OptionTreeItem's
Creating custom tree controls is a difficult and drawn out process, but I do not want this to deter you from
taking on the task. If you are an beginner program
and have ideas for new controls, please let me know and I will see what I can do. If you are and advanced programmer and have created customized controls, please let
me also know and I will include them in the next release. Some overrides you made need to know for OptionTreeItem
are below, you can look at some of the
code for the controls I have created to get an idea of how they are managed. Each control type, requires a different attack angle to implement it. A good place to start is to
take a look at OptionTreeItemStatic
, this is a simple control. OptionTreeItemEdit
is a good place to go after you look at the static item.
void OptionTreeItem::DrawAttribute(CDC *pDC, const RECT &rcRect)
void OptionTreeItem::OnActivate()
void OptionTreeItem::OnCommit()
void OptionTreeItem::OnMove()
void OptionTreeItem::OnMove()
void OptionTreeItem::OnSelect()
void OptionTreeItem::OnDeSelect()
void OptionTreeItem::CleanDestroyWindow()
Acknowledgements
The COptionTree is inspired by code, ideas, and submissions from the following:
Version History
Below is the version history for COptionTree.
5/7/2002
|
1.0.0.0 |
Initial implementation. |
|
5/10/2002 |
1.1.0.0 |
Fix problems with icon and color items. Also fixed problems with expanding columns and column size. Added TAB support, hit TAB to activate next item, and SHIFT TAB to activate previous item. NOTE: You must commit current item with the ENTER key before tabbing, this is because some controls use TAB i.e.) edit, control box, radio, and so on. |
|
5/11/2002 |
1.1.1.0 |
Fixed IsWindow() issues, which are the causes for a lot of Win98 problems. Fixed IDC_HAND problem for non Win 2K or XP users. Fixed some resource and overhead problems. Also added expand all feature. Huge thanks go out to all bug reporters, especially YoSilver. |
|
5/14/2002 |
1.1.2.0 |
Fixed icon and color bug. Also added GetItemType() to determine different item types. |
|
9/1/2002 |
1.1.2.1 |
Beta release, beta is not stable by any means. |
|
9/8/2002 |
2.0.0.0 |
The long awaited 2.0 version is here. Fixed a lot of bugs, created more bugs, added several more items, and a lot of other stuff that is way too much to list here. Oh plus I added fancy new version numbers, this I think was the biggest update. |
Bug Reports
If you have a bug report, or a bug fix you can contact me through email or with the forums below. I would appreciate a notification of any bugs discovered or improvements that could be made to help the control grow for everyone.
License
This code is provided "as is" with no expressed or implied warranty.
You may use this code in a commercial product with or without acknowledgement. However you may not sell this code or any modification of this code, this includes commercial libraries and anything else for profit.