Declare Function ExtractIcon Lib "shell32.dll" Alias "ExtractIconA" (ByVal hInst as Long, ByVal lpszExeFileName As String, ByVal nIconIndex As Long) As Long
ExtractIcon extracts a single icon from a file. This file can be an executable (.exe) file, a dynamic link library (.dll), or an icon file (.ico). Alternately, this function can also determine how many icons are stored in such a file. The icon generated by this function must be destroyed using DestroyIcon after the program has finished using it.
If the function failed because the specified file was not found, the function returns 1. If the function failed because the icon requested by the function did not exist, the function returns 0. If the function succeeded and the number of icons in the file was requested, the function returns the number of icons stored in the file. If the function succeeded and an icon was specified, the function returns a handle to the extracted icon.
None.
' This code is licensed according to the terms and conditions listed here.
' Display the first icon (index 0) stored in the executable file
' C:\MyApp\Prog.exe on window Form1. The icon must be destroyed after the
' program finishes using it.
Dim hIcon As Long ' handle to the function gotten from the executable file
Dim retval As Long ' return value
' Extract the first icon stored in the aforementioned executable file.
hIcon = ExtractIcon(App.hInstance, "C:\MyApp\Prog.exe", 0)
' Only attempt to display the icon if we successfully extracted it.
If hIcon = 0 Then
Debug.Print "Failed to extract the icon -- aborting."
End ' terminate the program
Else
' Display the icon at coordinates (100, 75) on window Form1.
retval = DrawIcon(Form1.hDC, 100, 75, hIcon)
' Although the icon's image is still visible, the icon itself is not in use.
' Therefore we destroy it to free up resources.
retval = DestroyIcon(hIcon)
End If
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: August 4, 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/extracticon.html