?
Solved

How to insert icons in listview?

Posted on 2003-10-29
3
Medium Priority
?
319 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 500 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 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