![]() |
|
QA: How can I get file extension icon?
By Alexander Shargin, March 19, 2003.
QuestionI want to write my own Open File dialog. How can I get file icon? AnswerBackgroundSystem 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. So how can I get it?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. Where do indices in the system image list come from?You can get index of icon associated with a specific file or folder using SHGetFileInfo function: One word of warningSince 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. DiscussDiscuss this article. Here you can write your comments and read comments of other developers. |
|||||||||||||||||||||