HOWTO: Obtain Icon Information from an .EXE in Windows 95Last reviewed: January 9, 1998Article ID: Q131500 |
The information in this article applies to:
SUMMARYSHGetFileInfo is a new API that Windows 95 provides to allow an application to extract icon information from a particular file. With the introduction of large (32x32) and small (16x16) icons in Windows 95, SHGetFileInfo provides this information as well by filling in the appropriate members of the SHFILEINFO structure.
MORE INFORMATIONIn Windows version 3.1, an application can use the ExtractIcon() to retrieve the handle of an icon associated with a specified executable file, dynamic link library, or icon file. Windows 95 provides a new function, SHGetFileInfo(), which, among other things, provides this icon information when using the SHGFI_ICON flag. When the function returns, the handle to the icon is returned in the hIcon member of the SHFILEINFO structure, and the index of the icon within the system image list is returned in the iIcon member of the same structure. The code below demonstrates how to retrieve the Gen32 sample's icon and associates that icon with a dialog box's button:
HICON hGen32Icon; SHFILEINFO shfi; if (SHGetFileInfo ((LPCSTR)"C:\\MySamplesDir\\Gen32\\Gen32.Exe", 0, &shfi, sizeof (SHFILEINFO), SHGFI_ICON)) { hGen32Icon = shfi.hIcon; // Note that this button has been defined in the .RC file // to be of BS_ICON style SendDlgItemMessage (hDlg, IDC_BUTTON, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)(HICON)hGen32Icon); } else { // SHGetFileInfo failed... }Windows 95 also introduces the concept of large and small icons associated with applications where the large icon is displayed when the application is minimized and the small icon is displayed in the upper-left corner of the application. This small icon, when clicked, drops down the application's system menu. SHGetFileInfo() provides the file's large and small icon information as well, using the SHGFI_LARGEICON and SHGFI_SMALLICON flags respectively. SHGFI_LARGEICON returns the handle of the system image list containing the large icon images, whereas SHGFI_SMALLICON returns that of the system image list containing the small icon images. These flags, when OR'ed with the SHGFI_SYSICONINDEX flag, return the icon index within the appropriate system image list in the iIcon member of the SHFILEINFO struct. The code sample below demonstrates how to retrieve the small icon associated with the same GEN32 sample.
HICON hGen32Icon; HIMAGELIST hSysImageList; SHFILEINFO shfi; hSysImageList = SHGetFileInfo((LPCSTR)"C:\\MySamplesDir\\Gen32\\Gen32.Exe", 0, &shfi, sizeof (SHFILEINFO), SHGFI_SYSICONINDEX | SHGFI_SMALLICON); if (hSysImageList) { hGen32Icon = ImageList_GetIcon (hSysImageList, shfi.iIcon, ILD_NORMAL); } else { // SHGetFileInfo failed... }Before closing, the application must call DestroyIcon() to free system resources associated with the icon returned by ImageList_GetIcon(). NOTE: The SHGetFileInfo() API will be supported in the next release of Windows NT that supports the new shell interface very similar to Windows 95. This API is not supported in Windows NT version 3.51.
|
Additional query words: DLL EXE ICO 32 x 32 16 x 16
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |