I have a list view report style. Im trying to sort by click on a header. For some reason it does nothing.
This Peice of code is invoked when the column is clicked.
if (pnm->hdr.code == LVN_COLUMNCLICK)
{
//DialogBoxParam(ghInstance, MAKEINTRESOURCE(IDD_SORT),
// NULL, (DLGPROC)SortDlgProc, 0);
if(nSortDir[pnm->iSubItem])
nSortDir[pnm->iSubItem] = false;
else
nSortDir[pnm->iSubItem] = true;
ListView_SortItems (hList, ListViewCompareProc, pnm->iSubItem);
nItem1=0;
return 0;
}
Now Here is my Call back function
int CALLBACK ListViewCompareProc (LPARAM lParam1, LPARAM lParam2, LPARAM
lParamSort)
{
static LV_FINDINFO fi;
static int nItem1, nItem2;
static char szBuf1[30], szBuf2[30];
// Determine the items that we are comparing.
//...........................................
fi.flags = LVFI_PARAM;
fi.lParam = lParam1;
nItem1 = ListView_FindItem(hList, -1, &fi);
fi.lParam = lParam2;
nItem2 = ListView_FindItem(hList, -1, &fi);
// Retrieve the item text so we can compare it.
//.............................................
ListView_GetItemText(hList, nItem1, lParamSort, szBuf1,
sizeof(szBuf1));
ListView_GetItemText(hList, nItem2, lParamSort, szBuf2,
sizeof(szBuf2));
// Return the comparison results.
//...............................
if (nSortDir[lParamSort] ) // ACENDING ORDER
return(strcmp(szBuf1, szBuf2));
else
return(strcmp(szBuf1, szBuf2) * -1);
}
According to MSDN, the Sort Macro should handle the results of the callback just like strcmp, and switch the items accordingly. Once again, the callback function is called and works, yet it does not sort properly, what could be wrong?