在MSDN里有关于SortItems的排序程序如下:// Sort the item in reverse alphabetical order.
static int CALLBACK
MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// lParamSort contains a pointer to the list view control.
// The lParam of an item is just its index.
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0); return strcmp(strItem2, strItem1);
}void snip_CListCtrl_SortItems()
{
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl; // Sort the list view items using my callback procedure.
pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
}
我仿照这些了一个,发现MyCompareProc中的lParam1和lParam2的值在比较的时候始终都是0这是为什么阿(另外我的list里是有内容的阿)请指教!!!!
BOOL SetItemData(
int nItem,
DWORD_PTR dwData
);
Res
This value is the lParam member of the LVITEM structure, as described in the Platform SDK.
比如:
for (int i=0;i < pmyListCtrl->GetItemCount();i++)
{
pmyListCtrl->SetItemData(i, i);
}
此处采用了简单的数据,要完整排序,需采用LVITEM结构充当第二个参数。具体参考MSDN.另:在控件中去掉自动排序风格功能。