HOWTO: Retrieve an Icon for a File Class Without a File

Last reviewed: January 9, 1998
Article ID: Q179167
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with: - Microsoft Windows NT 4.0 - Microsoft Windows 95

SUMMARY

This article explains how to use the SHGetFileInfo API to retrieve the icon for a file class without having a specific file of that class available.

MORE INFORMATION

To do this, select the SHGFI_USEFILEATTRIBUTES flag and FILE_ATTRIBUTE_NORMAL so that the API assumes that the file exists and it will not try to look for it on disk.

For example, to find the icon associated with ".zip" files the call would look like:

   SHFILEINFO sfi;
   HIMAGELIST hil;

   ZeroMemory(&sfi,sizeof(sfi));
   hil = SHGetFileInfo(".zip",
                       FILE_ATTRIBUTE_NORMAL,
                       &sfi,
                       sizeof(sfi),
                       SHGFI_USEFILEATTRIBUTES|SHGFI_ICON);

   // hil now contains the handle to the system image list
   // containing the large icon images.
   // sfi.hIcon contains the large icon for the file.

MORE INFORMATION

For additional information about the SHGetFileInfo API, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q131500
   TITLE     : HOWTO: Obtain Icon Information from an .EXE in Windows 95
Keywords          : UsrRes UsrShell
Version           : WINNT:4.0
Platform          : Win95 winnt
Issue type        : kbhowto


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 9, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.