Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Resources
Icons
Icon Reference
Functions
 ExtractIcon Function
ExtractIcon Function

The ExtractIcon function retrieves a handle to an icon from the specified executable file, DLL, or icon file.

To retrieve an array of handles to large or small icons, use the ExtractIconEx function.

Syntax

HICON ExtractIcon(      
    HINSTANCE hInst,     LPCTSTR lpszExeFileName,     UINT nIconIndex );

Parameters

hInst
[in] Handle to the instance of the application calling the function.
lpszExeFileName
[in] Pointer to a null-terminated string specifying the name of an executable file, DLL, or icon file.
nIconIndex
[in] Specifies the zero-based index of the icon to retrieve. For example, if this value is 0, the function returns a handle to the first icon in the specified file.

If this value is -1, the function returns the total number of icons in the specified file. If the file is an executable file or DLL, the return value is the number of RT_GROUP_ICON resources. If the file is an .ICO file, the return value is 1.

Windows 95/98/Me, Windows NT 4.0 and later: If this value is a negative number not equal to –1, the function returns a handle to the icon in the specified file whose resource identifier is equal to the absolute value of nIconIndex. For example, you should use –3 to extract the icon whose resource identifier is 3. To extract the icon whose resource identifier is 1, use the ExtractIconEx function.

Return Value

The return value is a handle to an icon. If the file specified was not an executable file, DLL, or icon file, the return is 1. If no icons were found in the file, the return value is NULL.

Remarks

This function is not supported for icons in 16-bit executables and DLLs.

You must destroy the icon handle returned by ExtractIcon by calling the DestroyIcon function.

Windows 95/98/Me: ExtractIconW is supported by the Microsoft Layer for Unicode (MSLU). To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

Function Information

Minimum DLL Versionshell32.dll
HeaderDeclared in Shellapi.h
Import libraryShell32.lib
Minimum operating systems Windows 95, Windows NT 3.1
UnicodeImplemented as ANSI and Unicode versions.

See Also

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Example wrapper in C#      infomax   |   Edit   |   Show History
For an example of how to use ExtractIcon within a C# wrapper see: Using Shell Icons
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker