Getting the 16×16 and 32×32 icons on Windows is relatively easy and is often as simple as one call to ExtractIconEx.
However, getting the extra large (48×48) and jumbo (256×256) icons introduced respectively by XP and Vista is slighly more complex. This is normally done by:
- Getting the file information, in particular the icon index, for the given file using SHGetFileInfo
- Retrieving the system image list where all the icons are stored
- Casting the image list to an IImageList interface and getting the icon from there
Below is the code I’m using in Appetizer to retrieve the extra large icon. If needed it can easily be adapted to get the jumbo icon.
Update: To do the same thing in C#, see the link in the comments below.
- #include <shlobj.h>
- #include <shlguid.h>
- #include <shellapi.h>
- #include <commctrl.h>
- #include <commoncontrols.h>
- // Get the icon index using SHGetFileInfo
- SHFILEINFOW sfi = {0};
- SHGetFileInfo(filePath, -1, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX);
- // Retrieve the system image list.
- // To get the 48x48 icons, use SHIL_EXTRALARGE
- // To get the 256x256 icons (Vista only), use SHIL_JUMBO
- HIMAGELIST* imageList;
- HRESULT hResult = SHGetImageList(SHIL_EXTRALARGE, IID_IImageList, (void**)&imageList);
- if (hResult == S_OK) {
- // Get the icon we need from the list. Note that the HIMAGELIST we retrieved
- // earlier needs to be casted to the IImageList interface before use.
- HICON hIcon;
- hResult = ((IImageList*)imageList)->GetIcon(sfi.iIcon, ILD_TRANSPARENT, &hIcon);
- if (hResult == S_OK) {
- // Do something with the icon here.
- // For example, in wxWidgets:
- wxIcon* icon = new wxIcon();
- icon->SetHICON((WXHICON)hIcon);
- icon->SetSize(48, 48);
- }
- }
Source:http://pogopixels.com/blog/getting-the-48x48-or-256x256-icon-of-a-file-on-windows/