#include "stdafx.h"
extern HWND g_hListBox;
int CALLBACK ListViewCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) {
static char szBuf1[100], szBuf2[100];
extern int nSortDir[14];//[7];
int i1, i2;
//=================================== Retrieve the item text so we can compare it.
ListView_GetItemText(g_hListBox, lParam1, (int)lParamSort, szBuf1, sizeof(szBuf1));
ListView_GetItemText(g_hListBox, lParam2, (int)lParamSort, szBuf2, sizeof(szBuf2));
//============================================= Then Return the Comparison Results.
if((lParamSort == 5)||(lParamSort >= 7)) { // Sort Only PageCount Columns 5 and 7
i1 = strtol(szBuf1, 0, 10); //-+++--> & up as a Number. Columns 4 & below and
i2 = strtol(szBuf2, 0, 10); //--+++--> 6 are Sorted as Words (alphabetically).
if(nSortDir[lParamSort]) //========= Toggle Between ASCENDING & DESCENDING ORDER
return i1-i2; //====================================== Sort Order ASCENDING
else // Thanks Eóin - From DonationCoder.com
return i2-i1;// <--Good/Bad--> i1+i2; //============= Sort Order DESCENDING
}else{ //========================= Sort ALL the Rest (Alphabetically) as a String.
if(nSortDir[lParamSort]) //========= Toggle Between ASCENDING & DESCENDING ORDER
return(_stricmp(szBuf1, szBuf2) * -1); //=============== Sort Order ASCENDING
else
return(_stricmp(szBuf1, szBuf2)); //=================== Sort Order DESCENDING
}
}
// Check to see if Alpha or Num Sort Locks up more/less/same
/* Note: This resolved a tendence to periodically sort things incorrectly
Eóin Re: ListView Control Hangs during Sort
« Reply #4 on: 10/7/2009 at 04:49:47 PM »
-------------------------------------------
A ListView will hang if the CompareProc returns
inconsistent results, eg a < b < c but c < a.
In the code posted there seems to be a logic error
in line 20, really seems like it should be return i2-i1;
*/