Solved

CListCtrl.SortItems question...

Posted on 1998-10-20
1
398 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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