Solved

CListCtrl.SortItems question...

Posted on 1998-10-20
1
380 Views
Last Modified: 2013-11-20
CListCtrl.SortItems(CompareFunc, dwData)
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lpara);

I use debugger to step inside the 'CompareFunc' and find out
lParam1 and lParam2 are both 0!!!!! However, lpara has the correct value. WHY????
0
Comment
Question by:stephenkong
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 0 total points
ID: 1323605
lParam1 and lParam2 are the item data associated with the two items being compared.

If you don't set item data then it's zero

To set item data with an item - use SetItemData member of CListCtrl.

The normal way way to do this is
1. In dwData pass a "pseudo" this ptr to the class
SortItems( CompareFunc, (LPARAM)this ) ;

2. In CompareFunc convert this back to a CListCtrl *, or a ptr to your derived class
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lpara)
{
 CListCtrl * pList = (CListCtrl *)lpara ;
}

3. To get non-zero item data
EITHER
(a) Set the row-id as item data for each item in the list before doing SortItems - then in CompareFunc you the item data as a param to GetItemText
OR
(b) Set the item data to point to some structure (you allocate) containing comparison data which the sort function uses

4. BTW if you want CompareFuncs to be a class member, make it a static member


Here's an example - that uses method 3(b).  Previous to this I have set item data with a record id for an AAInfo record (which is my data structure).  GetAA is a function I wrote to get an AAInfo record.  m_nSortColumn and m_bSortReverse are an int and BOOL class member

void CTComply::SortList()
{
      CWaitCursor oWait ;
      m_list.SortItems( CTComply::CompareFunc, (DWORD)this ) ;
}

nt CALLBACK CTComply::CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
      CTComply * pComply = (CTComply *)lParamSort ;
      ASSERT_VALID( pComply ) ;

      AAInfo oInfo1 ;
      AAInfo oInfo2 ;

      // get 2 items
      VERIFY( GetAA( lParam1, oInfo1 ) ) ;
      VERIFY( GetAA( lParam2, oInfo2 ) ) ;


      // now get 2 strings
      CString str1 ;
      CString str2 ;

      switch ( pComply->m_nSortColumn )
      {
      default :
      case 0 :
            str1 = oInfo1.m_strManufacturer ;
            str2 = oInfo2.m_strManufacturer ;
            break ;

      case 1 :
            str1 = oInfo1.m_strProduct ;
            str2 = oInfo2.m_strProduct ;
            break ;

      case 2 :
            str1 = oInfo1.m_strVersion ;
            str2 = oInfo2.m_strVersion ;
            break ;

      case 3 :
            str1 = oInfo1.m_strProductType ;
            str2 = oInfo2.m_strProductType ;
            break ;

      case 4 :
            str1 = oInfo1.GetStatus() ;
            str2 = oInfo2.GetStatus() ;
            break ;
      }


      // do comparison
      int nn = 0 ;

      if ( str1 < str2 ) nn = -1 ;
      if ( str1 > str2 ) nn = 1 ;

      if ( pComply->m_bSortReverse )
      {
            nn = 0 - nn ;
      }

      return nn ;
}

void CTComply::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
      NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

      int nNewHeader = pNMListView->iSubItem ;

      if ( nNewHeader == m_nSortColumn )
      {
            m_bSortReverse = !m_bSortReverse ;
      }
      m_nSortColumn = nNewHeader ;
      SortList() ;

      *pResult = 0;
}





0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
repeatEnd java challenge 42 85
zeroFront challenge 7 121
Problem to App source 6 89
c++  placing data into a form and an editbox 5 21
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question