DrawIcon Function

Declare Function DrawIcon Lib "user32.dll" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As Long

Platforms

Description & Usage

DrawIcon displays an icon on a device. The icon's position is determined by a coordinate pair passed to the function identifying the coordinates of the upper-left corner of the icon. The icon is always drawn in its normal dimensions.

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

hDC
A handle to a device context to the device to draw the icon on.
x
The x-coordinate of the point to position the upper-left corner of the icon's image at.
y
The y-coordinate of the point to position the upper-left corner of the icon's image at.
hIcon
A handle to the icon to display.

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

See Also

DrawIconEx

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/drawicon.html