Link to home
Start Free TrialLog in
Avatar of wooper
wooper

asked on

CListCtrl sorting with sortItem method...

I would like to use the sortItem method provided with the CListCtrl. But when I trace inside my comparision function:
"int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)"

"lParam1" and "lParam2" are null. Maybe the lParamSort should be used ? Can anyone give me a sample of code on how using this function ? Thanks.
Avatar of Zoppo
Zoppo
Flag of Germany image

Hi wooper,

The sample code in the MSDN help for CListCtrl::SortItems() should not work. Cause:

The CListCtrl::SortItems() function uses the LVM_SORTITEMS message to sort the list items. Sorting with this message passes the user defined item data (to set with CListCtrl::SetItemData) to the given compare function.
There also exists a LVM_SORTITEMSEX message, which sorts the items by passing the item id's to the given compare function. There is no CListCtrl-wrapper function for this message, but you can use ListView_SortItemsEx() macro to sort the list.

hope that helps,

ZOPPO
Avatar of wooper
wooper

ASKER

Hmm...  the Visual v4.0 doesn't reconize the "ListView_SortItemsEx()" macro.
Moreover, when I want to use the "ListView_SortItems" macro instead of the "ListView_SortItemsEx()", the compiler sent me a strange error message:

"error C2660: 'SendMessageA' : function does not take 4 parameters"

It's a non sense ?!?

The macro seems to be already there, so...

Here is the code I've used to call it:

HWND a = m_list.GetSafeHwnd();
PFNLVCOMPARE b = CompareFunc;
LPARAM c = dwData;
ListView_SortItems(a, b, c);

What's wrong ?
ASKER CERTIFIED SOLUTION
Avatar of danny_pav
danny_pav

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, found out that LVM_SORTITEMSEX requires InternetExplore > 5.0.

The error with the macro seems to be that the macro uses SendMessage instead of ::SendMessage.

So danny_pav's answer is correct.