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
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.
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.
When passing 0 explicitly as phiconLarge or phiconSmall, the 0 must be preceeded by the ByVal keyword. See the example for a demonstration.
' 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
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