ExtractIconEx Function

Declare Function ExtractIconEx Lib "shell32.dll" Alias "ExtractIconExA" (ByVal lpszFile As String, ByVal nIconIndex As Long, phiconLarge As Long, phiconSmall As Long, ByVal nIcons As Long) As Long

Platforms

Description & Usage

ExtractIconEx extracts multiple icons from a file. This file can be an executable file (.exe), a dynamic link library (.dll), or an icon file (.ico). This function can extract both large and small icons, whose handles are placed into two arrays. Optionally, this function can also determine how many large/small icon pairs are stores in such a file. Each icon which this function extracts must be destroyed using DestroyIcon after the program has finished using it.

Return Value

If nIconIndex is set to -1, phiconLarge is set to 0, and phiconSmall is set to 0, the function returns the number of icons stored in the file specified. Otherwise, the function returns the number of icons successfully extracted from the file.

Visual Basic-Specific Issues

When passing 0 explicitly as phiconLarge or phiconSmall, the 0 must be preceeded by the ByVal keyword. See the example for a demonstration.

Parameters

lpszFile
The name of the .exe, .dll, or .ico file to extract the icons from.
nIconIndex
The zero-based index of the first icon to extract from the file. If this is -1 and both phiconLarge and phiconSmall are 0, the function returns the number of icons stored in the file. Windows 95, 98, NT 4.0 or later, 2000: If this is a negative integer and at least either phiconLarge or phiconSmall (or both) are not zero, the function first extracts the icon whose resource identifier equals the absolute value of this parameter.
phiconLarge
An array which receives the handles of the large icons extracted from the file. To not extract any large icons, pass 0 as this parameter.
phiconSmall
An array which receives the handles of the small icons extracted from the file. To not extract any small icons, pass 0 as this parameter.
nIcons
The number of icons to extract from the file. Icons are extracted sequentially, beginning with the icon identified by nIconIndex.

Example

' This code is licensed according to the terms and conditions listed here.

' Extract all of the regular-sized icons from the file
' C:\MyApp\Prog.exe.  Display them in a row, stretching or shrinking them to
' a width of 32 and a height of 64.  Note how dynamically allocated arrays
' are used to receive the icon handles.  Draw all icons on a light-gray
' background on the window Form1.
Dim hIcons() As Long  ' dynamic array to receive handles to the icons
Dim numicons As Long  ' number of regular icons in the file
Dim hBrush As Long  ' handle to the background brush to use
Dim c As Long  ' counter variable
Dim retval As Long  ' return value

' Determine how many regular icons exist in the file and resize
' the array accordingly.
numicons = ExtractIconEx("C:\MyApp\Prog.exe", -1, ByVal 0, ByVal 0, 0)
If numicons = 0 Then
  Debug.Print "No icons found in the file -- aborting."
  End  ' abort the program if failure occurs
End If
ReDim hIcons(0 To numicons - 1) As Long  ' resize the array to hold all the handles
' Get a handle to the stock solid light gray brush to use for the background.
hBrush = GetStockObject(LTGRAY_BRUSH)  ' handle to the brush

' Extract all of the icons to display.
retval = ExtractIconEx("C:\MyApp\Prog.exe", numicons, hIcons(0), ByVal 0, 0)

' Loop through each icon, displaying it as previously mentioned.
For c = 0 To numicons - 1
  ' The x coordinate equals 32 * c.  The y coordinate is always 0.
  ' Display this particular icon.
  retval = DrawIconEx(Form1.hDC, 32 * c, 0, hIcons(c), 32, 64, 0, hBrush, DI_NORMAL)
  ' Now destroy this icon since we no longer are using it.
  retval = DestroyIcon(hIcons(c))
Next c

See Also

ExtractIcon

Category

Icons

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: August 5, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/e/extracticonex.html