CShellList - A Good ImageList Class
Environment: VC++
Part of this class was specifically designed for all the projects out there that need an imagelist that will retrieve system file icons, just like the explorer-like example provided. CShellList is much simpler than using shell namespace objects which only bring frustation and confusion.
The other part of the class was designed to retrieve all the system file type icons. This part of the class is fixed to work with IE6 Preview Edition which created problems with SHGetFileInfo when it registered the CDF file type
Inside the class are comments on how to use the functions, and the example project should show you how to tie in the class with your project.
Updated on July 28, 2001
- Added System Image List attaching and detaching functions
- Fixed CDF for all preview releases of IE6
Downloads
Download demo project - 28 KbDownload source - 52 Kb

Comments
make it clearly
Posted by xfrunning on 07/10/2007 04:55amyou must make it clearly or we will not understand
ReplyHow can i do it without MFC ??
Posted by Legacy on 12/22/2002 12:00amOriginally posted by: yuval
ReplyThanks, but found a little bug in the sample
Posted by Legacy on 12/20/2002 12:00amOriginally posted by: Bing Mou
The sample you provided does not initialize the COM library when start. It can be done by placing a call CoInitialize(NULL) at the beginning of InitInstance(). With out initializing the COM library, this sample won't be able to get icons of file-types that have custom icon handlers on NT based systems including Windows XP.
File type ".cdf" is an example. The icon for this type is neither stored in the IEXPLORE.EXE nor can be retrieved from the SHELL32.DLL. There is a custom icon handler for this file type and the handler is a COM object. You have to load the icon handler and get the icon through COM interface IShellIcon and IExtractIcon. Wait, you don't have to do it your-self, Windows API SHGetFileInfo that CShellList is using knows how to deal with it. All you needs to do is to initialize the COM library, or SHGetFileInfo will return you the default file icon.
ReplyHow do i get different icons for different exe's
Posted by Legacy on 09/25/2002 12:00amOriginally posted by: Gargoyle
When using this shell list i get a standard icon for all exes what i want to do is get individual exe icons for each exe like explorer does can anybody explain how to do this. in my list control i have a seperate call for files which have the .exe extention. butdon't know how to retrive the correct icon can anyone help. Thanks in advance
ReplyHow to get the handle to each of the images in an ImageList
Posted by Legacy on 07/18/2002 12:00amOriginally posted by: weiwei wang
Hi everyone,
I want to add several bmps to the CImageList
and then I want to get the handle to each of
the image in the CImageList.Do you know how to realize
it?
Thanks a lot. :)
Replyconverting .bmp to .jpg
Posted by Legacy on 03/31/2002 12:00amOriginally posted by: samar
how do i convert .bmp to jpg files?
ReplyHow do i convert .bmp files into .jpg files using VC++ programmign
Posted by Legacy on 02/04/2002 12:00amOriginally posted by: Rambhavan Verma
Dear sir,
Replythis is rambhavan verma here.
Please try to give me some suggestions/solutions on the above mentioned page title.
I have to do one project on the above mentioned topic.If you can help me then try to send me some code or any suggestions on the respective topic.
Thanking you,
Rambhavan Verma.
"Great part of Codeguru"
Posted by Legacy on 09/07/2001 12:00amOriginally posted by: Gopidi SureshReddy
ReplyNice, but...
Posted by Legacy on 06/26/2001 12:00amOriginally posted by: Thomas Freudenberg
CShellList is a fine class, but it may not show correct shell icons in some cases.
You are able to change the standard icons used by the shell. E.g. a closed folder icon is the 3rd in shell32.dll. By setting the registry key
<pre>
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Icons]
"3"="C:\\MyIcons.dll,7"
</pre>
you can specify a different icon. Therefore, I have added an additional method to your class:
<pre>
HICON CShellList::GetShellIcon( int nIndex )
{
HICON hIcon = NULL;
HKEY hkeyShellIcons;
if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), 0, KEY_READ, &hkeyShellIcons) == ERROR_SUCCESS)
{
TCHAR szBuffer[ MAX_PATH * sizeof TCHAR];
DWORD dwSize = MAX_PATH * sizeof TCHAR;
TCHAR szIndex[4];
wsprintf( szIndex, _T("%d"), nIndex );
if (RegQueryValueEx( hkeyShellIcons, szIndex, NULL, NULL, (LPBYTE)szBuffer, &dwSize) == ERROR_SUCCESS)
{
CString strFile, strIndex;
AfxExtractSubString( strFile, szBuffer, 0, _T(',') );
AfxExtractSubString( strIndex, szBuffer, 1, _T(',') );
ExtractIconEx( strFile, atoi(strIndex), NULL, &hIcon, 1 );
}
RegCloseKey( hkeyShellIcons );
}
// Add folder images
if (!hIcon)
ExtractIconEx(_T("SHELL32.DLL"), nIndex, NULL, &hIcon, 1);
return hIcon;
}</pre>
I have implemented it just regarding to my needs (I need the small icons only), so it neither returns a CShellList::LSICON nor it reads the large icons, but it's easy to extend.
Regards,
ReplyThomas