API for MFC Sorting Controls
SortListBox

Copyright © 2016 by David Wincelberg

Window Styles

Recommended horizontal scroll, vertical scroll, disable no scroll
Optional sort

For an owner-draw list box with strings, select has-strings and implement DrawItem and MeasureItem. CompareItem will not be called.

ExtentCalcs: list box horizontal extent calculations

CExtentCalcs();

constructor

void DeferExtentCalc (bool bDefer);

Defers or may call updating the maximum extent.

bDefer true for defer; false for updating maximum extent

void RecalcHorizontalExtent();

Recalculates and sets the list-box's horizontal extent.

void FontsChanged();

Recalculates extents if the font resources have changed.
The top-level window receives the OnFontChange message. It should pass it to list-box controls with extent calculations.

ListBoxData

CListBoxData();

constructor

ListBoxOrder

CListBoxOrder (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 (CString& strItem1, CListBoxData* pData1, CString& strItem2, CListBoxData* pData2);

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

strItem1 reference to the first string
pData1 pointer to the first data item
strItem2 reference to the second string
pData2 pointer to the second data item

SortListBox

CSortListBox (CListBoxOrder* pListBoxOrder = nullptr, bool bHandleDelete = true);

constructor

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

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

constructor

pListBoxOrder 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 (CListBoxOrder* pListBoxOrder, bool bHandleDelete = true);

Sets the sort-order to the specified value.

pListBoxOrder 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

int AddString (LPCTSTR lpszItem, CListBoxData* pListBoxData = nullptr);
int InsertString (int nIndex, LPCTSTR lpszItem, CListBoxData* pListBoxData = nullptr);

Same as for CListBox with an optional parameter for specifying a list-box data item

int DeleteString (UINT nIndex);
void ResetContent();
int SetItemData (int nIndex, DWORD dwItemData);
DWORD GetItemData (int nIndex) const;
int SetItemDataPtr (int nIndex, void* pData);
void* GetItemDataPtr (int nIndex) const;

Same as for CListBox

int SetItemDataObjPtr (int nIndex, CListBoxData* pListBoxData);

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

nIndex index into the list box
pListBoxData pointer to a data object

CListBoxData* GetItemDataObjPtr (int nIndex) const;

Retrieves user data as a pointer to a CListBoxData object.

nIndex index into the list box