Solved

ShellGetIconIndexFromExt/Listview

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

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

19 Experts available now in Live!

Get 1:1 Help Now