Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  3 781

•  TDictionary Custom Sort  5 895

•  Fast Watermark Sources  5 690

•  3D Designer  8 463

•  Sik Screen Capture  6 028

•  Patch Maker  6 471

•  Айболит (remote control)  6 465

•  ListBox Drag & Drop  5 328

•  Доска для игры Реверси  94 898

•  Графические эффекты  6 673

•  Рисование по маске  5 780

•  Перетаскивание изображений  4 850

•  Canvas Drawing  5 227

•  Рисование Луны  4 947

•  Поворот изображения  4 490

•  Рисование стержней  3 183

•  Paint on Shape  2 426

•  Генератор кроссвордов  3 304

•  Головоломка Paletto  2 613

•  Теорема Монжа об окружностях  3 397

•  Пазл Numbrix  2 246

•  Заборы и коммивояжеры  2 905

•  Игра HIP  1 874

•  Игра Go (Го)  1 786

•  Симулятор лифта  2 122

•  Программа укладки плитки  1 854

•  Генератор лабиринта  2 292

•  Проверка числового ввода  1 980

•  HEX View  2 289

•  Физический маятник  1 954

 
скрыть

  Форум  

Delphi FAQ - Часто задаваемые вопросы

| Базы данных | Графика и Игры | Интернет и Сети | Компоненты и Классы | Мультимедиа |
| ОС и Железо | Программа и Интерфейс | Рабочий стол | Синтаксис | Технологии | Файловая система |



Delphi Sources

Показать файлы с ассоциированными с ними иконками в TListView



Оформил: DeeCo

{ 
  The following example shows how to show all files and their 
  associated icons of a folder in a TListView. 
  To test the code, you need a ListView1 and a ImageList1 where the icons are stored. 

  Im folgenden Beispiel werden alle Dateien & zugehorigen 
  Icons eines Verzeichnisses in einer TListView angezeigt. 
  Um das Beispiel zu testen, braucht man eine ListView1 und eine ImageList1 
  Komponente, wo die Icons gespeichert werden. 
}


 uses
   ShellApi;

 procedure LV_InsertFiles(strPath: string; ListView: TListView; ImageList: TImageList);
 var
   i: Integer;
   Icon: TIcon;
   SearchRec: TSearchRec;
   ListItem: TListItem;
   FileInfo: SHFILEINFO;
 begin
   // Create a temporary TIcon 
  Icon := TIcon.Create;
   ListView.Items.BeginUpdate;
   try
     // search for the first file 
    i := FindFirst(strPath + '*.*', faAnyFile, SearchRec);
     while i = 0 do
     begin
       with ListView do
       begin
         // On directories and volumes 
        if ((SearchRec.Attr and FaDirectory <> FaDirectory) and
           (SearchRec.Attr and FaVolumeId <> FaVolumeID)) then
         begin
           ListItem := ListView.Items.Add;
           //Get The DisplayName 
          SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
             SizeOf(FileInfo), SHGFI_DISPLAYNAME);
           Listitem.Caption := FileInfo.szDisplayName;
           // Get The TypeName 
          SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
             SizeOf(FileInfo), SHGFI_TYPENAME);
           ListItem.SubItems.Add(FileInfo.szTypeName);
           //Get The Icon That Represents The File 
          SHGetFileInfo(PChar(strPath + SearchRec.Name), 0, FileInfo,
             SizeOf(FileInfo), SHGFI_ICON or SHGFI_SMALLICON);
           icon.Handle := FileInfo.hIcon;
           ListItem.ImageIndex := ImageList.AddIcon(Icon);
           // Destroy the Icon 
          DestroyIcon(FileInfo.hIcon);
         end;
       end;
       i := FindNext(SearchRec);
     end;
   finally
     Icon.Free;
     ListView.Items.EndUpdate;
   end;
 end;

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   // Assign a Imagelist to the ListView 
  ListView1.SmallImages := ImageList1;
   // Show Listview in Report Style and add 2 Columns 
  ListView1.ViewStyle := vsReport;
   ListView1.Columns.Add;
   ListView1.Columns.Add;
   LV_InsertFiles('C:\Windows\', ListView1, ImageList1);
 end;







Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте