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 Kb
Download source - 52 Kb



Comments

  • make it clearly

    Posted by xfrunning on 07/10/2007 04:55am

    you must make it clearly or we will not understand

    Reply
  • How can i do it without MFC ??

    Posted by Legacy on 12/22/2002 12:00am

    Originally posted by: yuval

    i tried to find a win32 system call for attach method ,but could not find one .
    
    how can i do it without the use of CImageList ?
    thanks,
    yuval

    Reply
  • Thanks, but found a little bug in the sample

    Posted by Legacy on 12/20/2002 12:00am

    Originally 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.

    Reply
  • How do i get different icons for different exe's

    Posted by Legacy on 09/25/2002 12:00am

    Originally 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

    Reply
  • How to get the handle to each of the images in an ImageList

    Posted by Legacy on 07/18/2002 12:00am

    Originally 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. :)

    Reply
  • converting .bmp to .jpg

    Posted by Legacy on 03/31/2002 12:00am

    Originally posted by: samar

    how do i convert .bmp to jpg files?

    Reply
  • How do i convert .bmp files into .jpg files using VC++ programmign

    Posted by Legacy on 02/04/2002 12:00am

    Originally posted by: Rambhavan Verma

    Dear sir,
    this 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.

    Reply
  • "Great part of Codeguru"

    Posted by Legacy on 09/07/2001 12:00am

    Originally posted by: Gopidi SureshReddy

    dear Nathan Moinvaziri,
    
    

    i am regular visitor of the site.I want to know How to use Dll of VC++ in ASP,there is any build in interface or we should write interface.


    thanking you ,

    bye bye

    suresh

    Reply
  • Nice, but...

    Posted by Legacy on 06/26/2001 12:00am

    Originally 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,
    Thomas

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Wednesday, September 24, 2014 8:00 AM - 9:00 AM PDT According to a recent Forrester Research report, many companies are choosing low-code platforms over traditional programming platforms, due to the speed with which low-code apps can be assembled and tested. With customer-facing applications on the rise, traditional programming platforms simply can't keep up with the "short schedules and rapid change cycles" required to develop these applications. Check out this upcoming webinar and join Clay Richardson from …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds