ListCtrl ,Sort

feiyanghu 2003-02-17 04:07:03
有没有关于ListCtrl中排序的代码,对文件按时间,大小,类型
...全文
70 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
feiyanghu 2003-02-19
  • 打赏
  • 举报
回复
hwbjx@sohu.com
wang790729 2003-02-17
  • 打赏
  • 举报
回复
我有一个类可以解决你的问题,你要是要的话就留下Email
niu_a 2003-02-17
  • 打赏
  • 举报
回复
CListCtrl::SortItems
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.

Remarks
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设置(第二个参数)

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧