有没有关于ListCtrl中排序的代码,对文件按时间,大小,类型
解决方案 »
- VC主框架与视图
- 严肃点! 问个问题(在线&立结)
- CString.Format(....)里那些格式标准有没有文章介绍啊?
- 关於CString的问题
- 最近看什么事什么人都不顺眼,严重影响本人日常行为,有许多关键的问题需要处理,特此散分以求有好的运气
- socket阻塞和非阻塞,用哪种方式好?
- 关于IE Cache的API函数
- 我想要一个能显示bmp,jpg等图象格式的控件,哪位朋友能给我一个吗?
- 用VC6.0 ADO 执行MSSQL2000里的存储过程失败的问题
- 问题好棘手哟,急需请教高手,分要多少我都给了!!!!!!!!!!!!!!!
- ==MDI下更改窗口标题的问题??===
- 如何将一个CString 对象强制转化为一个char*型的指针
This method sorts list view items using an application-defined comparison function. The index of each item changes to reflect the new sequence.
BOOL SortItems(
PFNLVCOMPARE pfnCompare,
DWORD dwData );
Parameters
pfnCompare
Specifies the address of the application-defined comparison function. The comparison function is called during the sort operation each time the relative order of two list items needs to be compared. The comparison function must be either a static member of a class or a standalone function that is not a member of any class.
dwData
Specifies the application-defined value that is passed to the comparison function.
Return Value
Nonzero if it is successful; otherwise, it is zero.
Res
The comparison function has the following form:
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamSort);
The comparison function must return a negative value if the first item should precede the second, a positive value if the first item should follow the second, or zero if the two items are equivalent.
The lParam1 and lParam2 parameters specify the item data for the two items being compared. The lParamSort parameter is the same as the dwData value.
Example
// 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.
CListCtrl* pmyListCtrl;
// Sort the list view items using my callback procedure.
pmyListCtrl- >SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
}
comparefunc的lparam1,lpram2 就是lvitem 的lParam项,在insertitem的时候设置,或者用SetItemData设置(第二个参数)