LVM_SORTITEMS

下面测试代码完全可以使用LVM_SORTITEMSEX代替,而且不需要设置lParam。

#define expect(condition, r) if ((condition) != (r)) return r;
static INT WINAPI test_CallBackCompare(LPARAM first, LPARAM second, LPARAM lParam)
{
    if (first == second) return 0;
	CHAR str1[5] = {0};
	CHAR str2[5] = {0};
	INT r = 0;
	HWND hwnd = (HWND)lParam;
    LV_ITEMA item = {0};
    item.cchTextMax = 5;
    item.iSubItem = 0;
    item.pszText = str1;
    r = SendMessageA(hwnd, LVM_GETITEMTEXTA, first, (LPARAM)&item);
    expect(TRUE, r);

    item.pszText = str2;
    r = SendMessageA(hwnd, LVM_GETITEMTEXTA, second, (LPARAM)&item);
    expect(TRUE, r);
	return atoi(str1) > atoi(str2)? 1 : (atoi(str1) == atoi(str2) ? 0: -1);
}

INT test_sort(HWND hwnd_listview)
{
	static CHAR before_sort_array[][5] = {"6","3","1","4","2"};
	static CHAR after_sort_arary[][5] = {"1","2","3","4","6"};
	INT r = 0;
	LV_ITEMA item = {0};
	item.mask = LVIF_PARAM | LVIF_TEXT;
	item.iSubItem = 0;
	item.cchTextMax = 5;

	INT i = 0;
	for (i = 0; i < sizeof(before_sort_array)/5; i++)
	{
    	item.iItem = i;
    	item.lParam = i;
    	item.pszText = &before_sort_array[i][0];
    	r = SendMessageA(hwnd_listview, LVM_INSERTITEMA, 0, (LPARAM) &item);
    	expect(i, r);
	}

	r = SendMessageA(hwnd_listview, LVM_SORTITEMS, (WPARAM)(LPARAM)hwnd_listview, (LPARAM)test_CallBackCompare);
	expect(TRUE, r);

	for (i = 0; i < sizeof(before_sort_array)/5; i++)
	{
    	CHAR str[5];
    	item.iItem = i;
    	item.cchTextMax = 5;
    	item.iSubItem = 0;
    	item.pszText = str;
    	r = SendMessageA(hwnd_listview, LVM_GETITEMTEXTA, i, (LPARAM)&item);
    	expect(TRUE, r);

    	expect(0, strcmp(str, &after_sort_arary[i][0]));
	}
	MessageBoxW(0,L"ok",L"ok",0);
	return 1;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值