//------------------------------------------------------------------------------
//把FileList中文件的图标加到ImageList中去
function GetFilesImageToList(ImageList: TImageList; FileName: string;
IsSmallIcon: Boolean): Boolean;
var
F_icon: TIcon;
shinfo: TSHFILEINFO;
isCreateFile: Boolean;
flag: Integer;
begin
F_icon := TIcon.Create;
if FileName <> '' then if FileName[1] = '"' then Delete(FileName, 1, 1);
if FileName <> '' then
if FileName[Length(FileName)] = '"' then
FileName := Copy(FileName, 1, Length(FileName) - 1);
isCreateFile := False;
if not FileExists(FileName) then
begin
FileName := GetWindowsTempDirectory + '/' + ExtractFileName(FileName);
if not FileExists(FileName) then isCreateFile := MyFileCreate(FileName);
end;
if IsSmallIcon then flag := (SHGFI_SMALLICON or SHGFI_ICON)
else flag := (SHGFI_LARGEICON or SHGFI_ICON);
SHGetFileInfo(PChar(FileName), 0, shinfo, Sizeof(shinfo), flag);
F_icon.Handle := shinfo.hIcon;
ImageList.AddIcon(F_icon); //把ICO装入ImageList中
if isCreateFile then
ZsFileUtils.MyDeleteFile(FileName);
F_icon.Free;
Result := True;
end;
function GetFilesImageToList(ImageList: TImageList; fileList: TStringList;
IsSmallIcon: Boolean): Boolean;
var i: Integer;
begin
ImageList.Clear;
if IsSmallIcon then ImageList.Height := 16
else ImageList.Height := 32;
ImageList.Width := ImageList.Height;
for i := 0 to fileList.Count - 1 do
GetFilesImageToList(ImageList, fileList, IsSmallIcon);
Result := True;
end;