Click here to Skip to main content
16,022,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I was wondering whether someone knows how to get the image of the icons on our Windows desktops (see the screenshot below). For example a handle to HBITMAP or just raw bits or the .png source file.
I need that image in order to save it to a PNG file.

Link to screenshot

What I have tried:

Acquiring the ImageList for the PROGMAN SysListView32 but it's always NULL.
Posted
Updated 5-Oct-24 1:51am
v4

The icons on the desktop are shortcuts to actual applications. So you need to get the properties of the shortcut to find the actual application: see IShellLinkA (shobjidl_core.h) - Win32 apps | Microsoft Learn[^] . You can then extract the icon from the application executable.

[edit]
See Finding and Loading Resources - Win32 apps | Microsoft Learn[^] for information on extracting resource items from an executable file.
[/edit]
 
Share this answer
 
v2
Comments
merano99 6-Oct-24 23:49pm    
The file name with path can be found with your suggestion, which is a good start. Unfortunately, you haven't mentioned how to extract icons and convert them to png. There are files like outlook.exe that seem to contain many icons, but I have not yet found a way to load them with C++.
[no name] 7-Oct-24 4:02am    
Solution updated.
Avtem 7-Oct-24 13:19pm    
I didn't have time to study this answer thoughtfully yet, but it led to the desired result with ChatGTP's help. Below is the magical image list which has most of the icons on my desktop:
HIMAGELIST hSysImageList = (HIMAGELIST)SHGetFileInfo(L"C:\\", 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_ICON);
[no name] 7-Oct-24 15:18pm    
Very interesting, I have not used that actual function, so will do some more research.
Avtem 7-Oct-24 22:38pm    
If you are interested, here is the full code for the program written by ChatGTP and finally fixed by me: https://drive.google.com/file/d/12OV_Wltc9Q3wfAkJmXUclewJ_Z3kp3LR/view?usp=sharing
With the help of ChatGTP I found a great solution that works great for me.
It turns out that there is an image list associated with the desktop ListView, but acquiring that list is really vague and mysterious:
C++
HIMAGELIST hSysImageList = (HIMAGELIST)SHGetFileInfo(L"C:\\", 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX | SHGFI_ICON); // sfi is just an empty SHFILEINFO struct.
If you enumerate every single image from that list you'll see that it has almost all icons from your desktop.

There is one downside though: as you can see in my original question, the file in second column is a file, for which Shell generated a preview (it works pretty much for all images, videos, pdfs, etc.). This list does not contain those previews.
Edit: I found some info on this topic: StackOverflow link

Big thanks to Richard MacCutchan whose suggestion lead me to this solution.
Edit: Full demo code you can find here: link
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900