Knowledge Base

How To Retrieve an Icon for a File Class Without a File

Article ID: 179167

Article Last Modified on 11/21/2006


APPLIES TO


This article was previously published under Q179167

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.
				

REFERENCES

Keywords: kbhowto KB179167