Solved

How to insert icons in listview?

Posted on 2003-10-29
3
316 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to center only a line in richedit? 4 69
Delphi selector screen 2 92
Convert a string into a TDateTime 5 72
Find and Replace Stream with 0s 8 73
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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