Solved

How to insert icons in listview?

Posted on 2003-10-29
3
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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 is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

717 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