Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CListBox::CompareItem()

CListBox::CompareItem()

Scheduled Pinned Locked Moved C / C++ / MFC
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gokings
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • G gokings

      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

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      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/[^]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups