Alexander Shargin (rudankort@softspb.com), March 19, 2003.
I want to write my own Open File dialog. How can I get file icon?
System image list is an image list used by operating system for its purposes. For example, the system stores all file and folder icons in its image list and use it when this information must be displayed to the user. If you are writing custom file selection control or some other application which needs to display icons associated with files, using system image list will greatly simplify this task.
Here is a function that returns a handle to the system image list:
Note: If you need large icons instead of small ones, use SHGFI_LARGEICON flag instead of SHGFI_SMALLICON.
If you are using MFC, you can then attach handle returned by this function to a CImageList class object.
You can get index of icon associated with a specific file or folder using SHGetFileInfo function:
Since system image list is created by the system do not destroy it in your program. If you have previously attached it to a CImageList class object, use CImageList::Detach when you no longer need it to prevent CImageList destructor from destroying the list.