I'm working on a program which shows a number of files with the appropriate icon from the system image list, with a custom overlay to indicate if a file has been added or deleted. The files are displayed in a tree view.
I'm using the following code to set the tree view's icon list:
HIMAGELIST himlIcons;
SHFILEINFO ssfi;
himlIcons = (HIMAGELIST)SHGetFileInfo(".",0,&ssfi,sizeof(SHFILEINFO),SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
ImageList_SetOverlayImage(himlIcons,ImageList_AddIcon(himlIcons, LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(IDI_DELETED))),1);
ImageList_SetOverlayImage(himlIcons,ImageList_AddIcon(himlIcons, LoadIcon(GetModuleHandle(0),MAKEINTRESOURCE(IDI_NEW))),2);
TreeView_SetImageList(hwndTV, himlIcons, LVSIL_NORMAL);
I then use this function to determine which icon should be displayed for a given file name that is to be added to the tree view:
int GetIconIndex(int isdirectory, char *filename)
{
SHFILEINFO sfi;
SHGetFileInfo(filename,isdirectory ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL,&sfi,sizeof(SHFILEINFO),SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
return sfi.iIcon;
}
The problem is that adding my own icons to the system image list appears to break the list on Windows 2000. Incorrect base icons (not the overlays, those are fine) are displayed, both in my tree view and in f.e. the file-open and file-save dialogs.
This problem does not seem to occur on Windows XP.
My question; what is the correct way to have a custom icon overlay on images from the system image list in a tree view?