Solved

How to insert icons in listview?

Posted on 2003-10-29
3
310 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
Comment Utility
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
Comment Utility
let me check the code then i'll give you the points
0
 

Author Comment

by:dia21
Comment Utility
tnx for help
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now