Solved

ShellGetIconIndexFromExt/Listview

Posted on 2000-04-12
8
161 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 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
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…
Suggested Courses
Course of the Month5 days, 9 hours left to enroll

627 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