API for MFC Sorting Controls
SortListBox Owner Draw

Copyright 2016 by David Wincelberg

Window Styles

Required owner-draw variable
Recommended horizontal scroll, vertical scroll, disable no scroll
Optional sort
Prohibited owner-draw fixed, has strings (so sorting will call CompareItem)

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.

ListBoxODData

CListBoxODData (LPCTSTR lpszItem);

constructor

lpszItem pointer to a constant character string

void GetString (CString& rString);

Retrieves the string that is stored in this data object.

rString reference to a string

ListBoxODOrder

CListBoxODOrder (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 (CListBoxODData* pData1, CListBoxODData* pData2);

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

pData1 pointer to the first data item
pData2 pointer to the second data item

SortListBoxOD

CSortListBoxOD (CListBoxODOrder* pListBoxODOrder = nullptr, bool bHandleDelete = true);

constructor

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

CSortListBoxOD (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 (CListBoxODOrder* pListBoxODOrder, bool bHandleDelete = true);

Sets the sort-order to the specified value.

pListBoxODOrder 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 for a list box.

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

int AddString (LPCTSTR lpszItem, CListBoxODData* pListBoxODData = nullptr);
int InsertString (int nIndex, LPCTSTR lpszItem, CListBoxODData* pListBoxODData = nullptr);

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

int DeleteString (UINT nIndex);
int FindString (int nStartAfter, LPCTSTR lpszItem) const;
int FindStringExact (int nStartAfter, LPCTSTR lpszItem) const;
void GetText (int nIndex, CString& rString) const;
int GetText (int nIndex, LPTSTR lpszBuffer) const;
int GetTextLen (int nIndex) const;
int SelectString (int nStartAfter, LPCTSTR lpszItem);
void ResetContent();
void FontsChanged();
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, CListBoxODData* pListBoxODData);

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

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

CListBoxODData* GetItemDataObjPtr (int nIndex) const;

Retrieves user data as a pointer to a CListBoxODData object.

nIndex index into the list box