Estaba usando un código que
escafandra puso en otro foro para pintar flechas de ordenamiento en un TListView; el código es este:
Código:
int LastSortedColumn;
bool Ascending;
void SetSortIcon(TListView *ListView, int ColumnIndex, BOOL Orden)
{
HANDLE hHeader;
HD_ITEM HD;
hHeader = (HANDLE)SendMessage(ListView->Handle, LVM_GETHEADER, 0, 0);
for (int i = 0; i < ListView->Columns->Count; i++)
{
HD.mask = HDI_FORMAT;
SendMessage(hHeader, HDM_GETITEM, i, DWORD(&HD));
if (i == ColumnIndex)
{
if (Orden)
HD.fmt = (HD.fmt & ~HDF_SORTUP) | HDF_SORTDOWN;
else
HD.fmt = (HD.fmt & ~HDF_SORTDOWN) | HDF_SORTUP;
}
else
HD.fmt &= ~(HDF_SORTUP | HDF_SORTDOWN);
SendMessage(hHeader, HDM_SETITEM, i, DWORD(&HD));
}
}
//---------------------------------------------------------------------------
int __stdcall SortByColumn(long Item1, long Item2, long Data)
{
int w;
TListItem* item1 = reinterpret_cast<TListItem*>(Item1);
TListItem* item2 = reinterpret_cast<TListItem*>(Item2);
switch (item1->ListView->Column[Data]->Tag)
{
case 0: // Texto
if (Data == 0)
w = AnsiCompareText(item1->Caption, item2->Caption);
else
w = AnsiCompareText(item1->SubItems->Strings[Data - 1], item2->SubItems->Strings[Data - 1]);
break;
case 1: // Numérico
if (Data == 0)
w = item1->Caption.ToIntDef(0) - item2->Caption.ToIntDef(0);
else
w = item1->SubItems->Strings[Data - 1].ToIntDef(0) - item2->SubItems->Strings[Data - 1].ToIntDef(0);
break;
case 2: // Fecha
if (Data == 0)
w = StrToDateDef(item1->Caption, dFechaNula) - StrToDateDef(item2->Caption, dFechaNula);
else
w = StrToDateDef(item1->SubItems->Strings[Data - 1], dFechaNula) - StrToDateDef(item2->SubItems->Strings[Data - 1], dFechaNula);
break;
}
return Ascending ? w : -w;
}
//---------------------------------------------------------------------------
void __fastcall TfPersona::LisRecColumnClick(TObject *Sender, TListColumn *Column)
{
if (Column->Index == LastSortedColumn)
Ascending = !Ascending;
else
{
Ascending = true;
LastSortedColumn = Column->Index;
}
SetSortIcon(LisRec, Column->Index, Ascending);
static_cast<TListView *>(Sender)->CustomSort(SortByColumn, Column->Index);
}
//---------------------------------------------------------------------------
Funciona a la perfección, pero el aspecto del ListView no me convence porque la flecha se coloca en la parte superior de la columna y es poco visible.

¿Cómo habría que modificar el código para que se pintara, como suele ser habitual, en el lado derecho de la columna?