Solved

How to insert icons in listview?

Posted on 2003-10-29
3
315 Views
Last Modified: 2010-04-05
i want to insert shell icons for the files when i put them into a listview.
0
Comment
Question by:dia21
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
so3 earned 125 total points
ID: 9646593
you will need 2 listimages called SmallImages and LargeImages

procedure TForm1.FormCreate(Sender: TObject);
var SysIL: THandle;
    SFI:TSHFileInfo;
    SysSIL: THandle;
begin
 with SmallImages do begin
       SysSIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
        SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
      if SysSIL <> 0 then begin
        SmallImages.Handle := SysSIL;
        ShareImages := True;
      end;
    end;
   with LargeImages do begin
        SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI),
        SHGFI_SYSICONINDEX or SHGFI_LARGEICON);
       if SysIL <> 0 then begin
        LargeImages.Handle := SysIL;
        ShareImages := True;
      end;
    end;
end;

function Tform1.GetIconIndex(const AFile: string; Attrs: DWORD): integer;
var
  SFI: TSHFileInfo;
begin
  SHGetFileInfo(PChar(AFile), Attrs, SFI, SizeOf(TSHFileInfo),
    SHGFI_SYSICONINDEX or SHGFI_USEFILEATTRIBUTES);
  Result := SFI.iIcon;
end;

listview.Items.Add.ImageIndex:=Form1.GetIconIndex(Name,FILE_ATTRIBUTE_DIRECTORY) - for folders
or
listview.Items.Add.ImageIndex:=Form1.GetIconIndex(Name,FILE_ATTRIBUTE_NORMALE) - for files      

-were name is your filename or folder

0
 

Author Comment

by:dia21
ID: 9646619
let me check the code then i'll give you the points
0
 

Author Comment

by:dia21
ID: 9646652
tnx for help
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi XE10 Round Image 2 155
Run video youtube webbrowse 10 65
how can i search if string exist in array ? 3 63
Browsing a TTreeView in Delphi 5 7
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question