CListBox::CompareItem()
-
Does anyone happen to have a complete buildable project using ClistBox::CompareItem()? If I set the list box to "has strings", CompareItem() is never called. If I uncheck "has strings", then CompareItem() is called, but all the information in the COMPAREITEMSTRUCT regarding item 2 appears to be garbage. Thanks
-
Does anyone happen to have a complete buildable project using ClistBox::CompareItem()? If I set the list box to "has strings", CompareItem() is never called. If I uncheck "has strings", then CompareItem() is called, but all the information in the COMPAREITEMSTRUCT regarding item 2 appears to be garbage. Thanks
It's been a while since I used that, but I found some code for an owner-drawn CClassListBox (derived from CListBox) without "has strings", in which: I added items to the listbox using something like
int CClassListBox::AddItem(CFormClass* pClass)
{
ASSERT_VALID(pClass);
return AddString((char*) pClass);
}int CClassListBox::InsertItem(UINT nIndex, CFormClass* pClass)
{
ASSERT_VALID(pClass);
return InsertString(nIndex, (char*) pClass);
}then DrawItem, MeasureItem, CompareItem, etc., received these CFormClass pointers as the itemData fields. The CompareItem() implementation was:
int CClassListBox::CompareItem(LPCOMPAREITEMSTRUCT lpCIS)
{
CFormClass* pI1 = (CFormClass*) lpCIS->itemData1;
CFormClass* pI2 = (CFormClass*) lpCIS->itemData2;ASSERT\_VALID(pI1); ASSERT\_VALID(pI2); ASSERT(pI1->IsKindOf(RUNTIME\_CLASS(CFormClass))); ASSERT(pI2->IsKindOf(RUNTIME\_CLASS(CFormClass))); if (pI1->IsGraphic() && !pI2->IsGraphic()) return -1; if (!pI1->IsGraphic() && pI2->IsGraphic()) return 1; int i = stricmp(pI1->GetName(),pI2->GetName()); if (i < 0) i = -1; else if (i > 0) i = 1; return i;
}
Hope that helps, -- jlr http://jlamas.blogspot.com/[^]