Keeper89, спасибо!!! Но почему то не для всех файлов иконки вытягиваються, к примеру для файлов оперы иконка не вытягиваеться, в чем может быть дело?
| Код | unit main;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, FileCtrl, StdCtrls, ShellAPI, ComCtrls;
type TForm1 = class(TForm) ComboBox1: TComboBox; DirectoryListBox1: TDirectoryListBox; ListView1: TListView; DriveComboBox1: TDriveComboBox; procedure FormCreate(Sender: TObject); procedure DirectoryListBox1Change(Sender: TObject); procedure ComboBox1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure UpdateFiles; var sr: TSearchRec; li: TListItem; fi: TSHFileInfo; ext: string; IconIndex: word; ic: TIcon; begin Form1.ListView1.Items.BeginUpdate; Form1.ListView1.Items.Clear; if FindFirst(Form1.DirectoryListBox1.Directory + '\*.*', faAnyFile, sr) = 0 then repeat if sr.Attr and faDirectory <> 0 then continue; li := Form1.ListView1.Items.Add; li.Caption := sr.name; ic := TIcon.Create; try ext := LowerCase(ExtractFileExt(li.Caption)); SHGetFileInfo(PChar('*' + ext), FILE_ATTRIBUTE_NORMAL, fi, SizeOf(fi), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES ); ic.Handle := fi.hIcon; Form1.ListView1.SmallImages.AddIcon(ic); li.ImageIndex := Form1.ListView1.SmallImages.Count - 1; finally ic.Free; end; li.ImageIndex := fi.iIcon; if sr.Size < 1024 then li.SubItems.Add(IntToStr(sr.Size) + ' byte') else if sr.Size < 1024 * 1024 then li.SubItems.Add(IntToStr(round(sr.Size / 1024)) + ' KByte') else li.SubItems.Add(IntToStr(round(sr.Size / (1024 * 1024))) + ' MByte'); li.SubItems.Add(fi.szTypeName); until FindNext(sr) <> 0; FindClose(sr); Form1.ListView1.Items.EndUpdate; end;
procedure TForm1.FormCreate(Sender: TObject); var fi: TSHFileInfo; lc: TListColumn; begin DriveComboBox1.DirList := DirectoryListBox1; with ListView1 do begin SmallImages := TImageList.CreateSize(16,16); SmallImages.Handle := SHGetFileInfo('*.*', FILE_ATTRIBUTE_NORMAL, fi, SizeOf(fi), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES ); LargeImages := TImageList.Create(nil); LargeImages.Handle := SHGetFileInfo('*.*', FILE_ATTRIBUTE_NORMAL, fi, SizeOf(fi), SHGFI_ICON or SHGFI_SMALLICON or SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES ); lc := Columns.Add; lc.Caption := 'Name'; lc := Columns.Add; lc.Caption := 'Size'; ComboBox1.Items.Add('List'); ComboBox1.Items.Add('Icons'); ComboBox1.Items.Add('Table'); ComboBox1.Items.Add('SmallIcons'); ComboBox1.ItemIndex := 0; ListView1.ViewStyle := vsList; end; UpdateFiles; end;
procedure TForm1.DirectoryListBox1Change(Sender: TObject); begin UpdateFiles; end;
procedure TForm1.ComboBox1Click(Sender: TObject); begin case ComboBox1.ItemIndex of 0: ListView1.ViewStyle := vsIcon; 1: ListView1.ViewStyle := vsList; 2: ListView1.ViewStyle := vsReport; else ListView1.ViewStyle := vsSmallIcon;
end; end;
end.
|
|