在fraright这个frame中排序的方法:
procedure TfraRight.lisvWuColumnClick(Sender: TObject;
Column: TListColumn);
function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer; stdcall;
begin
case ParamSort of //Column
0://Sort Main column.
if AtoZOrder then
Result:=lstrcmp(PChar(TListItem(Item1).Caption), PChar(TListItem(Item2).Caption))
else
Result:=-lstrcmp(PChar(TListItem(Item1).Caption), PChar(TListItem(Item2).Caption));
else //Sort one of the subcolumns (subitems).
if AtoZOrder then
Result:=lstrcmp(PChar(TListItem(Item1).SubItems[ParamSort-1]), PChar(TListItem(Item2).SubItems[ParamSort-1]))
else
Result:=-lstrcmp(PChar(TListItem(Item1).SubItems[ParamSort-1]), PChar(TListItem(Item2).SubItems[ParamSort-1]));
end;
end;
var hditem:THdItem;
I: Byte;
begin
if OldCol=Column.Index then
FAtoZ:=not FAtoZ
else
OldCol:=Column.Index;
AtoZOrder:=FAtoZ;
lisvWu.CustomSort(@CustomSortProc, Column.Index);
for I:=0 to lisvWu.Columns.Count-1 do
begin
FBitmap.Releasehandle;
if I=Column.Index then
begin
if AtoZOrder then
FBitmap.Handle:=ArrowDown
else
FBitmap.Handle:=ArrowUp
end
else
FBitmap.Handle:=NoArrow;
hditem.Mask := HDI_FORMAT;
Header_GetItem(GetDlgItem(lisvWu.Handle,0),I,hditem);
hditem.Mask:=HDI_BITMAP or HDI_FORMAT;
hditem.fmt:=hditem.fmt or HDF_BITMAP;
hditem.hbm:=FBitmap.Handle;
Header_SetItem(GetDlgItem(lisvWu.Handle,0),I,hditem);
end;
end;
procedure TfraRight.FrameEnter(Sender: TObject);//初始化
begin
ArrowUp:=LoadBitmap(hInstance, 'ARROWUP');
ArrowDown:=LoadBitmap(hInstance, 'ARROWDOWN');
NoArrow:=LoadBitmap(hInstance, 'NOARROW');
FBitmap:=TBitmap.Create;
lisvWuColumnClick(Sender,lisvWu.Columns[0]);
end;
procedure TfraRight.FrameExit(Sender: TObject);//free
begin
FBitmap.ReleaseHandle;
FBitmap.Free;
DeleteObject(ArrowUp);
DeleteObject(ArrowDown);
DeleteObject(NoArrow);
end;