设置ListView的页眉图标

时间:2010-01-28 08:40:58  来源:第二电脑网  作者:第二电脑网

  第二电脑网导读:istView; mImages: TImageList): Boolean;varvHandle: THandle;begin  Result := False;  if not Assigned(mListView) then Exit;  vHandle := ListView_GetHeader(mListView.Handle);  if Assigned(mImages) then  Header_SetImageList(vHandle, mImages.Handle)  ...
  正文:(*//
标题:设置ListView的页眉图标
说明:可以用来做排序修饰图标
设计:Zswang
支持:wjhu111@21cn.com
日期:2004-03-25
//*)

uses CommCtrl;

function ListViewHeaderImages(mListView: TListView; mImages: TImageList): Boolean;
var
vHandle: THandle;
begin
  Result := False;
  if not Assigned(mListView) then Exit;
  vHandle := ListView_GetHeader(mListView.Handle);
  if Assigned(mImages) then
  Header_SetImageList(vHandle, mImages.Handle)
  else Header_SetImageList(vHandle, 0);
  Result := True;
end; { ListViewHeaderImages }

function ListColumnImageIndex(mColumn: TListColumn;
mImageIndex: Integer; mRight: Boolean = True): Boolean;
var
vHandle: THandle;
vHDItem: THDItem;
begin
  Result := False;
  if not Assigned(mColumn) then Exit;
  vHandle := ListView_GetHeader(TListView(mColumn.Collection.Owner).Handle);
  FillChar(vHDItem, SizeOf(vHDItem), 0);
  Header_GetItem(vHandle, mColumn.Index, vHDItem);
  if mImageIndex < 0 then begin
    vHDItem.Mask := HDI_FORMAT;
    vHDItem.fmt := HDF_STRING;
  end else begin
    vHDItem.Mask := HDI_IMAGE or HDI_FORMAT;
    vHDItem.iImage := mImageIndex;
    vHDItem.fmt := HDF_STRING or HDF_IMAGE or
    (HDF_BITMAP_ON_RIGHT * Ord(mRight));
  end;
  Header_SetItem(vHandle, mColumn.Index, vHDItem);
end; { ListColumnImageIndex }

//Example
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
{$J+}
const vIndex: Integer = 0;
{$J-}
var
I: Integer;
begin
  for I := 0 to TListView(Sender).Columns.Count - 1 do
  ListColumnImageIndex(TListView(Sender).Columns[I], -1);
  if Abs(vIndex) = Column.Index + 1 then
  vIndex := -vIndex
  else vIndex := Column.Index + 1;
  ListColumnImageIndex(Column, Ord(vIndex > 0));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ListViewHeaderImages(ListView1, ImageList1);
end;

"设置ListView的页眉图标"由第二电脑网原创提供,转载请注明:http://www.002pc.com/master/College/Language/Delphi/12538.html


关键字:

关于《设置ListView的页眉图标》文章的评论

站内搜索: 高级搜索

热门搜索: Windows style 系统 tr IP QQ CPU 安装 function 注册 if td