API for MFC Sorting Controls
SortCheckListBox

Copyright © 2016 by David Wincelberg

Window Styles

Required owner-draw fixed, has strings
Recommended horizontal scroll, vertical scroll, disable no scroll
Optional sort
Prohibited owner-draw variable

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

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

SortCheckListBox

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

constructor

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

CSortCheckListBox (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, bool bAddSpace = true, int nCheckDefault = 0, bool bHasCheckCode = false, CListBoxData* pListBoxData = nullptr);

Adds a string to the check list box.

lpszItem a string to be added
bAddSpace true for adding a space after the check boxes
nCheckDefault default check code: 0, 1 or 2
bHasCheckCode true if first characters of strings contains a check code
pListBoxData pointer to a CListBoxData object

int InsertString (int nIndex, LPCTSTR lpszItem, bool bAddSpace = true, int nCheckDefault = 0, bool bHasCheckCode = false, CListBoxData* pListBoxData = nullptr);

Inserts a string to a specified position in the check list box.

nIndex position to insert a string
lpszItem a string to be inserted
bAddSpace true for adding a space after the check boxes
nCheckDefault default check code: 0, 1 or 2
bHasCheckCode true if first characters of strings contain a check code
pListBoxData pointer to a CListBoxData object

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 CCheckListBox

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