DestroyIcon Function

Declare Function DestroyIcon Lib "user32.dll" (ByVal hIcon As Long) As Long

Platforms

Description & Usage

DestroyIcon destroys an icon and frees the memory which contained the icon. Some functions which provide an icon (sometimes but not necessarily creating it) require programs to use this function after using an icon, while others do not. Check the icon function in question to determine whether or not the icon must be destroyed. An icon cannot be in use when the program destroys it, whether it is used by the program or other programs.

Return Value

If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.

Visual Basic-Specific Issues

None.

Parameters

hIcon
A handle to the icon to destroy.

Example

' 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

Category

Icons

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/d/destroyicon.html