下面程序我调试过,ok
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,shellapi, ExtCtrls, StdCtrls, ComCtrls, ImgList;
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
TreeView1: TTreeView;
ImageList1: TImageList;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
ImageList:THandle;
FileInfo:TSHFileInfo;
TreeNode:TTreeNode;
begin
ImageList:=SHGetFileInfo('c:/',0,FileInfo,sizeof(FileInfo),SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
ImageList1.Handle:=ImageList;
ImageList1.ShareImages:=true;
SHGetFileInfo('.bmp',0,FileInfo,sizeof(FileInfo),SHGFI_USEFILEATTRIBUTES or SHGFI_ICON or SHGFI_SMALLICON);
TreeNode:=TreeView1.Items.Add(nil,'*.bmp');
TreeNode.ImageIndex :=FileInfo.iIcon;
end;
end.