Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ShellGetIconIndexFromExt/Listview

Posted on 2000-04-12
8
Medium Priority
?
163 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
[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
  • 6
  • 2
8 Comments
 
LVL 10

Accepted Solution

by:
Lischke earned 200 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
Independent Software Vendors: 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!

 

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

Technology Partners: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

688 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