I would like a function that takes any file path in Windows (any file system object--file, folder, drive, shortcut, etc.) and returns the associated .ICO file (or some handle to the icon with all image size representations). For example, if I specified 'C:\MyTextFile.txt' in Windows 7, I would get all of the 256x256, 48x48, 32x32, and 16x16 representations for the .txt file in an .ICO file, which is located in imageres.dll at offset 102:
^ The Icon tab installed by Stardock IconPackager, which locates the icon for the file system object
From my research so far, it doesn't appear to be that easy. There's the ExtractIconEx
function, but it only gives the 16 and 32px representations. There's also this post that shows how to get the SHIL_SMALL
, SHIL_LARGE
, SHIL_EXTRALARGE
, and SHIL_JUMBO
sizes, which are generally 16, 32, 48, and 256 pixels respectively. However, that doesn't necessarily cover other sizes that would be stored in the .ICO file as well. For example, some icons store 10 or more different sizes rather than just four.
So, I'm trying to:
- Find the location of the file system object's icon, and
- Retrieve it from the DLL, EXE, or whatever resource that encapsulates it.
I guess one question would be: Is this a task for the Windows registry? As you can see below, the registry's txtfile->DefaultIcon value contains the location of the icon for the .txt file type.
But, there are also standalone .exe files, for example, that self-contain an icon that wouldn't be stored in the registry.
Ultimately, I'd like to display all of the different sizes within a TImage and potentially output them together in an .ICO file. Any help would be appreciated.