Solved

ShellGetIconIndexFromExt/Listview

Posted on 2000-04-12
8
157 Views
Last Modified: 2010-08-05
I'm attempting to write an FTP client but I need some help with a procedure.

I have a listview for the remote file view and I need a procedure I can stick (for example only) in the change event, that will use "ShellGetIconIndexFromExt" or SOMETHING to assign an icon to the item being added. MEANING the file won't exist, so the icon needs to be retrieved using an unconventional method. Any help with this would be GREATLY appreciated and full credit will be given in my client when it is finished.

Thanks in advance!
0
Comment
Question by:Psylord
  • 6
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 50 total points
ID: 2711032
Hi Psylord,

I have not fully understood what you want. Is it that you need to set the correct (system) icon for a certain file or do you want to directly retrive the icon of the application (for remote files this will need some extra work)?

If you want to show the normal icons for all files in your listview (normal means here: the same icons as Explorer shows) then use the system's internal image list for the listview and pick the correct icon indices for each file:

procedure CreateImages;

var
  SysIL: HImageList;
  SFI: TSHFileInfo;
 
begin
  // Create an image list component
  MyListView.Images := TImageList.Create(Self);
  // This gets the small image list.  Replace SHGFI_SMALLICON with
  // SHGFI_LARGEICON for large images.
  SysIL := SHGetFileInfo('', 0, SFI, SizeOf(SFI), SHGFI_SYSICONINDEX or SHGFI_SMALLICON);
  if SysIL <> 0 then
  begin
    // Assign the system list to the component
    Images.Handle := SysIL;
    // The following prevents the image list handle from being
    // destroyed when the component is.
    Images.ShareImages := True;
  end;
end;

In order to get the correct icon index into the image list use:

function 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;

If the file physically exists and is accessible by the system then Attrs can be set to 0, because the true icon will be used (depending on the kind of file). If the file is not accessible then you need to set Attrs accordingly. Then the returned index is based on the file extension.

Ciao, Mike
0
 

Author Comment

by:Psylord
ID: 2714030
I think We're on the right track here.
To answer your question: "Is it that you need to set the correct (system) icon for a certain file or do you want to directly retrive the icon of the application (for remote files this will need some extra work)?" -- I want to "set the correct (system) icon for a certain file"

I tried using your code (which I appreciate!) but I'm guessing some things are missing from the uses clause? What do I need to add?

Best Regards,
Paul Swonger
0
 

Author Comment

by:Psylord
ID: 2714072
I've found the uses clauses (I apologize for my ignorance). For anyone reading they are:

ShellAPI, commctrl,
  ComCtrls

I think. :)

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

Author Comment

by:Psylord
ID: 2714096
I've found the uses clauses (I apologize for my ignorance). For anyone reading they are:

ShellAPI, commctrl,
  ComCtrls

I think. :)

0
 

Author Comment

by:Psylord
ID: 2714102
Ok... I think I've got it... But since the file does not exist... I would set Attrs to what?
0
 

Author Comment

by:Psylord
ID: 2714152
I've done it! Disregard all previous comments. I appreciate the help!

-Paul Swonger
0
 

Author Comment

by:Psylord
ID: 2714153
Excellent job.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2715149
Hey Psylord, very frequent posts here... I was sleeping a while, so I could not answer here :-). But I see you managed the missing parts yourself, so thank you for the A grading!

Have fun and

Ciao, Mike
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Multiple image collision 13 80
Dev express lookupcombo 3 35
Installshield for Embarcadero EX 10.1 Berlin 4 60
How to Get Images From Server to Client using App Tethering 1 27
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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

830 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