Click here to Skip to main content
15,892,269 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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:
C
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?
Posted
Updated 7-Nov-11 6:39am
v2
Comments
KarstenK 17-Nov-11 6:02am    
maybe it is a bug in Windows 2000. You better life with it...

1 solution

There is a bug in Windows 2000 and SHGetFileInfo() is not compatible with this version of the OS.
 
Share this answer
 

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