-1

In Delphi XE7, I need to get the LOCATION of the icon used by Windows Explorer to display a folder, especially in thumbnail view. So I use this code:

var
  Shell32DllFilePath: string;

// Get shell32.dll FilePath:
Shell32DllFilePath := IncludeTrailingPathDelimiter(JclSysInfo.GetWindowsSystemFolder) + 'shell32.dll';
if not FileExists(Shell32DllFilePath) then
begin
    Shell32DllFilePath := '';
    // Todo: log this error
end;

Then I ASSUME that the default folder icon is the icon with IconIndex 3 in shell32.dll:

enter image description here

However, this gives me a static image for every folder, while Windows Explorer uses different folder icons according to the folder location and/or the folder content.

So how can I get the exact folder icon location (icon dll file and icon index) Windows Explorer uses for any SPECIFIC folder?

user1580348
  • 5,721
  • 4
  • 43
  • 105
  • If I recall, there's a Windows API for this which does not consist of having to know where the actual icons are located. – Jerry Dodge Mar 09 '15 at 22:33
  • But I NEED to know where this icon is located, because I need those parameters to create a Shell Link (to a specific target file) with those icon parameters. – user1580348 Mar 09 '15 at 22:40
  • And if the Windows user customizes a folder and puts their own icon? – Jerry Dodge Mar 09 '15 at 22:43
  • Well, I could check that too. – user1580348 Mar 09 '15 at 22:51
  • 1
    When you are creating a Shell Link do you need an Icon as a file or is a handle to the Icon enough. Becouse as far as I know the API mentioned by Jerry Dodge (I forgot how it is called) does return an Icon handle. – SilverWarior Mar 09 '15 at 22:57
  • Where's the code where you attempt to obtain the icon. I cannot see how the code in the question relates to your problem. Or have you not got that far yet? Are you calling `SHGetFileInfo`? http://stackoverflow.com/questions/1703186/can-48x48-or-64x64-icons-be-obtained-from-the-vista-shell – David Heffernan Mar 09 '15 at 23:13
  • I don't need to get the icon itself, I need to get the icon LOCATION. – user1580348 Mar 09 '15 at 23:19
  • A folder can specify the location of its own icon via a [`desktop.ini`](https://msdn.microsoft.com/en-us/library/windows/desktop/cc144102.aspx) file within the folder itself, where the file contains `IconFile`/`IconIndex` or `IconResource` entries. If that file is missing, the folder displays a default icon, but even that is not static. For instance, if the folder has content, it might display one icon, even a dynamic preview of the content, but display another icon when empty. On Vista+, look at `SHGetStockIconInfo()`. – Remy Lebeau Mar 09 '15 at 23:20
  • Long story short, don't attempt to re-invent the wheel that Windows already established for you. If you try to do this yourself, there are many different things to be aware of. Also, you mention "especially in thumbnail view" which shows stacked images/icons. There's no such thing as a "location of the icon" in that scenario - it's created on the fly. That being said, can you please provide in your question a screenshot of such a folder icon so we can be sure that's what's meant by "thumbnail view"? – Jerry Dodge Mar 09 '15 at 23:27
  • @user Do you have evidence that is possible? – David Heffernan Mar 09 '15 at 23:47
  • Related: http://meta.stackoverflow.com/questions/287702/how-to-handle-good-questions-which-cannot-be-answered – Jerry Dodge Mar 09 '15 at 23:50
  • SHGetFileInfo with SHGFI_ICONLOCATION flag. – Denis Anisimov Mar 10 '15 at 10:22
  • Check out this question on SU http://superuser.com/questions/25086/where-are-my-icons-in-windows-7 – Michael Riley - AKA Gunny Mar 10 '15 at 11:05

1 Answers1

1

There may not be a file path to an icon with the way Windows works. You mention "especially in thumbnail view", which means images and icons (within the folder) are stacked together in the folder icon. This does not save a file anywhere, so you can't load from any file.

I'm assuming this is the type of icon you're talking about:

enter image description here

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • I agree it is not possible to get an icon location for the `thumbnail view`. But could it be possible for the `icon view`? – user1580348 Mar 10 '15 at 00:30
  • @user You need to ask a new question on that topic then. If you had asked how to obtain this icon, that's a different story. But you asked how to get the file path to where you can load the icon yourself (using code we cannot even see). – Jerry Dodge Mar 10 '15 at 00:37
  • Thumbnail view, icon view, ... What are these? What I see here is 'large icons', 'medium icons' etc.. Anything larger than 'small icons' have dynamically rendered content. – Sertac Akyuz Mar 10 '15 at 00:39
  • @SertacAkyuz I think that terminology is from XP. – Jerry Dodge Mar 10 '15 at 00:39
  • @Jerry - Thanks. Then perhaps there's no dynamic content in the context of the question? – Sertac Akyuz Mar 10 '15 at 00:42
  • @SertacAkyuz The screenshot provided in the question is from a later version of Windows (Vista+) and I understand the user to be asking how to accomplish the icon in my screenshot. They're the same folder icon, but the images are dynamically put into it. The use of the word "especially" puts emphasis on OP's desired behavior. – Jerry Dodge Mar 10 '15 at 00:43