lvm_sortitems with no MFC?
-
Hi, I have a custom listbox set up with several columns (file name, file type, size and path), and I want it so that whenever a user clicks on a column header, the items are sorted, just as in Windows Explorer, for instance. The column click part is easy, as I just have this code underneath case WM_NOTIFY:
case IDC_LIST1: //CHECK FOR COLUMN CLICK: if(((LPNMHDR)lParam)->code == LVN_COLUMNCLICK) { if(((LPNMLISTVIEW)lParam)->iSubItem == 0) { //need to sort items using LVM_SORTITEMS here... } }
However, I have no idea about how to use LVM_SORTITEMS. Obviously, I need to send it using SendDlgItemMessage and use a callback function as it says over on MSDN, but I don't know how to set up the callback function. The problem is that all of the examples I have found are MFC based, but I am _not_ using MFC, just the straight Windows API. Does anybody know where I can find a decent "sort listview items" code example that does not use MFC, or could anybody give me some pointers on how to go about it myself? Many thanks for any help, KB -
Hi, I have a custom listbox set up with several columns (file name, file type, size and path), and I want it so that whenever a user clicks on a column header, the items are sorted, just as in Windows Explorer, for instance. The column click part is easy, as I just have this code underneath case WM_NOTIFY:
case IDC_LIST1: //CHECK FOR COLUMN CLICK: if(((LPNMHDR)lParam)->code == LVN_COLUMNCLICK) { if(((LPNMLISTVIEW)lParam)->iSubItem == 0) { //need to sort items using LVM_SORTITEMS here... } }
However, I have no idea about how to use LVM_SORTITEMS. Obviously, I need to send it using SendDlgItemMessage and use a callback function as it says over on MSDN, but I don't know how to set up the callback function. The problem is that all of the examples I have found are MFC based, but I am _not_ using MFC, just the straight Windows API. Does anybody know where I can find a decent "sort listview items" code example that does not use MFC, or could anybody give me some pointers on how to go about it myself? Many thanks for any help, KBKayembi wrote: ...but I don't know how to set up the callback function. It has the following signature:
int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
The MSDN article Q170884 should give you some ideas, even though it's in VB. Basically, each item that is added to the list control has an associated item data (use theLVM_SETITEM
message for this). WhenCompareFunc()
is called,lParam1
points to one item's data andlParam2
points to another item's data. You have to castlParam1
andlParam2
to the appropriate type, and then do some sort of comparision.