I think you need to use CMFCHeaderCtrl::SetSortColumn to set the column's sort order. every time you sort. In addition to that, the actual sort function should be called from the HDN_ITEMCLICK handler.
So, assuming you have specified this:
ON_NOTIFY(HDN_ITEMCLICK, 0, OnItemclickList1)
In the OnItemclickList1 method write this code:
void CTest::OnItemclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
NMLISTVIEW *pLV = (NMLISTVIEW *) pNMHDR;
CMFCHeaderCtrl &headerCntrl = GetHeaderCtrl();
BOOL b = 0;
if(headerCntrl.IsAscending())
{
headerCntrl.SetSortColumn(pLV->iItem, FALSE);
SortItems(SortMeDescending, pLV->iItem);
}
else
{
headerCntrl.SetSortColumn(pLV->iItem, TRUE);
SortItems(SortMeAscending, iColumn);
}
*pResult = 0;
}
and ditch your OnCompareItems