다음을 통해 공유


CListBox::CompareItem

정렬 된 소유자 그리기 목록 상자에서 새 항목의 상대적 위치를 결정 하는 프레임 워크에서 호출 합니다.

virtual int CompareItem( 
   LPCOMPAREITEMSTRUCT lpCompareItemStruct  
);

매개 변수

  • lpCompareItemStruct
    하 긴 포인터는 COMPAREITEMSTRUCT 구조.

반환 값

에 설명 된 두 항목의 상대 위치를 나타내는 COMPAREITEMSTRUCT 구조. 다음 값 중 하나를 수 있습니다.

의미

–1

항목 1 항목 2 앞으로 정렬합니다.

0

항목 1과 항목 2는 정렬 합니다.

1

항목 1 항목 2 뒤를 정렬합니다.

참조 CWnd::OnCompareItem 에 있는 COMPAREITEMSTRUCT 구조.

설명

기본적으로이 함수는 실행 되지 않습니다. 소유자 그리기 목록 상자를 만들 경우는 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);
}

요구 사항

헤더: afxwin.h

참고 항목

참조

CListBox 클래스

계층 구조 차트

WM_COMPAREITEM

CWnd::OnCompareItem

CListBox::DrawItem

CListBox::MeasureItem

CListBox::DeleteItem