/*
* Note that PSESSION is my own instance data structure.
* I use it here to retrieve the type of field comparison I should do.
*/
static SHORT APIENTRY Compare (PMINIRECORDCORE pmrc1,
PMINIRECORDCORE pmrc2,
PVOID pvStorage)
{
PSESSION pSession = (PSESSION) pvStorage ;
PFIELDINFO pFieldInfo = pSession->pFieldInfoSort ;
PPVOID pField1 = (PPVOID) ((PBYTE) pmrc1 +
pFieldInfo->offStruct) ;
PPVOID pField2 = (PPVOID) ((PBYTE) pmrc2 +
pFieldInfo->offStruct) ;
SHORT sResult = 0 ;
if (pFieldInfo->flData & CFA_STRING) {
sResult = strcmp ((PCHAR) *pField1, (PCHAR) *pField2) ;
}
else if (pFieldInfo->flData & CFA_ULONG) {
if ((ULONG) *pField1 < (ULONG) *pField2)
sResult = -1 ;
else if ((ULONG) *pField1 > (ULONG) *pField2)
sResult = 1 ;
else
sResult = 0 ;
}
else if (pFieldInfo->flData & CFA_DATE) {
sResult = CompareDate ((PCDATE) (PVOID) pField1,
(PCDATE) (PVOID) pField2) ;
}
else if (pFieldInfo->flData & CFA_TIME) {
sResult = CompareTime ((PCTIME) (PVOID) pField1,
(PCTIME) (PVOID) pField2) ;
}
// Any other data type gets treated as equal;
// no sorting can be done. Now handle reverse sequence.
if (pSession->fSortReverse && sResult)
sResult = -sResult ;
return sResult ;
}
Here is how I invoke the sort:
// Send container a sort message.
ulRC = LONGFROMMR (WinSendMsg (
pSession->hwndContainer,
CM_SORTRECORD,
MPFROMP (Compare), MPFROMP (pSession))) ;
if (!ulRC) {
// Report error.
}
Credit: Wayne Kovsky