API for MFC Sorting Controls
SortTreeCtrl

Copyright © 2016 by David Wincelberg

Window Styles

All window styles are optional.

TreeCtrlData

CTreeCtrlData (LPCTSTR pText = nullptr, LPARAM lParam = 0);

constructor

pText pointer to a string
lParam application-specific data

void SetValues (LPCTSTR pText, LPARAM lParam = 0);

Sets the string and the application-specific data to the specified values.

pText pointer to a string
lParam application-specific data

virtual CString& GetText();

Returns the string.

void SetLParam (LPARAM lParam);

Sets the application-specific data to the specified value.

lParam application-specific data

LPARAM GetLParam() const;

Returns the application-specific data.

TreeCtrlOrder

CTreeCtrlOrder (CStringOrder* pStringOrder = nullptr, bool bHandleDelete = true);

constructor

pStringOrder pointer to a string-order object
bHandleDelete specifies whether to delete this string-order object

void SetStringOrder (CStringOrder* pStringOrder, bool bHandleDelete = true);

Sets the string-order to the specified value.

pStringOrder pointer to a string-order object
bHandleDelete specifies whether to delete this string-order object

bool ValidStringOrder()

Returns true if the string-order object is not null.

CStringOrder* GetStringOrder();

Returns the string-order object.

virtual int Compare (LPARAM lParam1, LPARAM lParam2);

Returns an integer that specifies order of the strings based on the corresponding data items.

lParam1 pointer to the first data item
lParam2 pointer to the second data item

SortTreeCtrl

CSortTreeCtrl (CTreeCtrlOrder* pTreeCtrlOrder = nullptr, bool bHandleDelete = true);

constructor

pTreeCtrlOrder pointer to a sort-order object
bHandleDelete specifies whether to delete this sort-order object

CSortTreeCtrl (CStringOrder* pStringOrder, bool bHandleDeleteInner = true, bool bHandleDeleteOuter = true);

constructor

pTreeCtrlOrder pointer to a string-order object
bHandleDeleteInner specifies whether to delete this string-order object
bHandleDeleteOuter specifies whether to delete the sort-order object

void SetSortOrder (CTreeCtrlOrder* pTreeCtrlOrder, bool bHandleDelete = true);

Sets the sort-order to the specified value.

pTreeCtrlOrder pointer to sort-order object
bHandleDelete specifies whether to delete this sort-order object

void SetStringOrder (CStringOrder* pStringOrder, bool bHandleDelete = true);

Sets the string-order to the specified value.

pStringOrder pointer to string-order object
bHandleDelete specifies whether to delete this string-order object

HTREEITEM InsertItem (LPCTSTR lpszItem, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST, CTreeCtrlData* pTreeCtrlData = nullptr);

HTREEITEM InsertItem (LPCTSTR lpszItem, int nImage, int nSelectedImage, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST, CTreeCtrlData* pTreeCtrlData = nullptr);

HTREEITEM InsertItem (UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent = TVI_ROOT, HTREEITEM hInsertAfter = TVI_LAST, CTreeCtrlData* pTreeCtrlData = nullptr);

HTREEITEM InsertItem (LPTVINSERTSTRUCT lpInsertStruct, CTreeCtrlData* pTreeCtrlData = nullptr);

Same as for CTreeCtrl with an optional parameter for specifying a tree-ctrl data item

BOOL DeleteItem (HTREEITEM hItem);
BOOL SortChildren (HTREEITEM hItem);
BOOL DeleteAllItems();
BOOL SetItemData (HTREEITEM hItem, DWORD dwData);
DWORD GetItemData (HTREEITEM hItem) const;

Same as for CTreeCtrl

BOOL SetItemDataObjPtr (HTREEITEM hItem, CTreeCtrlData* pTreeCtrlData);

Stores user data as a pointer to a CTreeCtrlData object.
Copies the data values from the old data object and deletes it. pTreeCtrlData should be from a subclass of CTreeCtrlData.

hItem handle to a tree-ctrl item
pTreeCtrlData pointer to a data object

CTreeCtrlData* GetItemDataObjPtr (HTREEITEM hItem) const;

Retrieves user data as a pointer to a CTreeCtrlData object.

hItem handle to a tree-ctrl item