用户登录  |  用户注册
首 页商业源码原创产品编程论坛
当前位置:PB创新网文章中心编程技巧Delphi

设置ListView的页眉图标

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2009-03-16 20:04:37
(*//
标题:设置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;

Tags:

作者:佚名

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
PB创新网ourmis.com】Copyright © 2000-2009 . All Rights Reserved .
页面执行时间:312.50000 毫秒
Email:ourmis@126.com QQ:2322888 蜀ICP备05006790号