afx_msg int OnCompareItem( LPCOMPAREITEMSTRUCT
lpCompareItemStruct );
lpCompareItemStruct
Contains a long pointer to a COMPAREITEMSTRUCT data structure that contains the identifiers and application-supplied data for two items in the combo or list box.
Override this member function in your derived class to handle the WM_COMPAREITEM message.
Use the overridden member function to specify the relative position of a new item in a sorted owner-draw combo or list box.
If a combo or list box is created with the CBS_SORT or LBS_SORT style, Windows sends the combo-box or list-box owner a WM_COMPAREITEM
message whenever the application adds a new item.
The lpCompareItemStruct parameter is a long pointer to a COMPAREITEMSTRUCT data structure that contains the identifiers and application-supplied data for two items in the combo or list box. OnCompareItem should return a value indicating which of the items should appear before the other. Typically, Windows makes this call several times until it determines the exact position for the new item.
A COMPAREITEMSTRUCT data structure has this form:
typedef struct tagCOMPAREITEMSTRUCT {
WORD CtlType;
WORD CtlID;
HWND hwndItem;
WORD itemID1;
DWORD itemData1;
WORD itemID2;
DWORD itemData2;
CtlType
ODT_LISTBOX (which specifies an owner-draw list box) or ODT_COMBOBOX (which specifies an owner-draw combo box).
CtlID
The control ID for the list box or combo box.
hwndItem
The window handle of the control.
itemID1
The index of the first item in the list box or combo box being compared.
itemData1
Application-supplied data for the first item being compared. This value was passed in the call that added the item to the combo or list box.
itemID2
Index of the second item in the list box or combo box being compared.
itemData2
Application-supplied data for the second item being compared. This value was passed in the call that added the item to the combo or list box.
This message-handler member function calls the Default member function.
Indicates the relative position of the two items. It may be any of the following values:
Value | Meaning |
-1 | Item 1 sorts before item 2. |
0 | Item 1 and item 2 sort the same. |
1 | Item 1 sorts after item 2. |
COMPAREITEMSTRUCT, WM_COMPAREITEM, CWnd::Default