编译联接均无问题,执行时也可以调用到排序回调函数但是发现回调函数的前两个参数(要比较的两项)传入为0,但第3个参数是正确的,请问什么原因?该如何解决?代码如下:定义排序回调函数
int CALLBACK CRealTimeView::RealTimeViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
CItem *pItem1 = (CAlarmItem*)lParam1;
CItem *pItem2 = (CAlarmItem*)lParam2;
int iResult = 0;
          .....
          .....
          .....
return iResult;
}创建LVN_COLUMNCLICK消息响应函数
void CAlarmRealTimeView::OnColumnclick(NMHDR* pNMHDR, LRESULT* pResult) 
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
// TODO: Add your control notification handler code here
CListCtrl& m_lst = GetListCtrl();
m_lst.SortItems(CRealTimeView::RealTimeViewCompareProc, pNMListView->iSubItem);
m_SelectItem = -1;

switch (pNMListView->iSubItem) {
case 0:
m_bSort0 = !m_bSort0;
break;
case 1:
m_bSort1 = !m_bSort1;
break;
case 2:
m_bSort2 = !m_bSort2;
break;
case 3:
m_bSort3 = !m_bSort3;
break;
case 4:
m_bSort4 = !m_bSort4;
break;
case 5:
m_bSort5 = !m_bSort5;
break;
case 6:
m_bSort6 = !m_bSort6;
break;
}

*pResult = 0;
}

解决方案 »

  1.   

    To sort items, use the LVM_SORTITEMS message. When you sort using this message, you specify an application-defined callback function that the list view control calls to compare the relative order of any two items. The control passes to the comparison function the item data associated with each of the two items. The item data is the value that was specified in the lParam member of the item's LVITEM structure when it was inserted into the list. By specifying the appropriate item data and supplying an appropriate comparison function, you can sort items by their label, by any subitem, or by any other property. Note that sorting items does not reorder the corresponding subitems. Thus, if any subitems are not callback items, you must regenerate the subitems after sorting. You can ensure that a list view control is always sorted by specifying the LVS_SORTASCENDING or LVS_SORTDESCENDING window style. Controls with these styles use the label text of the items to sort them in ascending or descending order. You cannot supply a comparison function when using these window styles. If a list view control has either of these styles, an LVM_INSERTITEM message will fail if you try to insert an item that has LPSTR_TEXTCALLBACK as the pszText member of its LVITEM structure. 
      

  2.   

    CItem *pItem1 = (CAlarmItem*)lParam1;
    CItem *pItem2 = (CAlarmItem*)lParam2;
    如果你没有SetItemData,又如何进行类型转换呢
      

  3.   

    那是因为你的lParam1,2都是空的啊,看看你其他的代码,有没有设置数据(SetItemData),或者就是指针没有指向你想指向的数据