CListBox::CompareItem

调用由框架确定新项目的相对位置在已排序的所有者描述列表框。

virtual int CompareItem( 
   LPCOMPAREITEMSTRUCT lpCompareItemStruct  
);

参数

  • lpCompareItemStruct
    COMPAREITEMSTRUCT framework的较长的指针。

返回值

指示在 COMPAREITEMSTRUCT 结构描述的两个项目的相对位置。 它可以是下列值中的任何一项:

含义

–1

project 1 project 2.之前排序。

0

project 1和2项排序相同。

1

project 1 project 2.后排序。

COMPAREITEMSTRUCT 结构的声明参见 CWnd::OnCompareItem

备注

默认情况下,此成员函数不执行任何操作。 如果创建具有所有者描述 LBS_SORT 样式的列表框,必须重写该成员函数的帮助在排序新的项目结构添加到列表框。

示例

// CMyODListBox is my owner-drawn list box derived from CListBox. This  
// example compares two items using _tcscmp to sort items in reverse  
// alphabetical order. The list box control was created with the  
// following code: 
//   m_myODListBox.Create( 
//      WS_CHILD|WS_VISIBLE|WS_BORDER|WS_HSCROLL|WS_VSCROLL| 
//      LBS_SORT|LBS_MULTIPLESEL|LBS_OWNERDRAWVARIABLE|LBS_WANTKEYBOARDINPUT, 
//      CRect(10,250,200,450), pParentWnd, IDC_MYODLISTBOX); 
// 
int CMyODListBox::CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct)
{
   ASSERT(lpCompareItemStruct->CtlType == ODT_LISTBOX);
   LPCTSTR lpszText1 = (LPCTSTR) lpCompareItemStruct->itemData1;
   ASSERT(lpszText1 != NULL);
   LPCTSTR lpszText2 = (LPCTSTR) lpCompareItemStruct->itemData2;
   ASSERT(lpszText2 != NULL);

   return _tcscmp(lpszText2, lpszText1);
}

要求

Header: afxwin.h

请参见

参考

CListBox Class

层次结构图

WM_COMPAREITEM

CWnd::OnCompareItem

CListBox::DrawItem

CListBox::MeasureItem

CListBox::DeleteItem