Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,712 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Now I have the index number of the icon (say 81).
How to get the icon using the index number,(I know that SHGetFileInfoW can get the icon directly),
I want to save the index and call it when I need it
For example, a test of Notepad icon :
SHFILEINFO sfi = { 0 };
HIMAGELIST hImageList = (HIMAGELIST)SHGetFileInfo(L"C:\\WINDOWS\\system32\\notepad.exe", 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX);
if (hImageList)
{
int nX = 10, nY = 10;
HDC hDC = GetDC(NULL);
DrawIconEx(hDC, nX, nY, ImageList_GetIcon(hImageList, sfi.iIcon, ILD_NORMAL), 0, 0, 0, NULL, DI_NORMAL);
ReleaseDC(NULL, hDC);
}
According to documentation and some articles, you can obtain the system image list using a code like this:
SHFILEINFO unused;
HIMAGELIST hSysImgList = (HIMAGELIST)SHGetFileInfo(
"C:",
FILE_ATTRIBUTE_NORMAL,
&unused,
sizeof(SHFILEINFO),
SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX | SHGFI_ICON);
The name of the file does not matter. Maybe you should also specify the SHGFI_SMALLICON flag.
Then use ImageList_GetIcon
to get the icon by index.