DrawIconEx Function

Declare Function DrawIconEx Lib "user32.dll" (ByVal hdc As Long, ByVal xLeft As Long, ByVal yTop As Long, ByVal hIcon As Long, ByVal cxWidth As Long, ByVal cyWidth As Long, ByVal istepIfAniCur As Long, ByVal hbrFlickerFreeDraw As Long, ByVal diFlags As Long) As Long

Platforms

Description & Usage

DrawIconEx displays either an icon or a cursor (or a single frame of an animated cursor) on a device. The image's position is determined by passing the coordinates of the upper-left corner of the image. The function can stretch the image in either direction as well as specify other display parameters.

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 or cursor on.
xLeft
The x-coordinate of the point to position the upper-left corner of the icon's or cursor's image at.
yTop
The y-coordinate of the point to position the upper-left corner of the icon's or cursor's image at.
hIcon
A handle to the icon or cursor to draw.
cxWidth
The width in pixels to stretch the icon's or cursor's image to. If this is 0, the image is drawn using either the icon's or cursor's width or the default width of the system, depending on the flags passed as diFlags.
cyWidth
The height in pixels to stretch the icon's or cursor's image to. If this is 0, the image is drawn using either the icon's or cursor's height or the default height of the system, depending on the flags passed as diFlags.
istepIfAniCursor
If hIcon is a handle to an animated cursor, this specifies the index of the particular frame to draw. Otherwise, this parameter is ignored.
hbrFlickerFreeDraw
A handle to the brush to use as the icon's or cursor's background. The background is added to the icon's or cursor's image using a flicker-free method. If this parameter is 0, the image is drawn directly onto the device without first adding a background.
diFlags
A combination of the following flags specifying how to draw the icon or cursor:
DI_COMPAT
Draw the icon or cursor using the system default image instead of the user-specified image.
DI_DEFAULTSIZE
If cxWidth and cyWidth are set to 0, draw the icon or cursor using the height and width settings defined by the system metrics. If this flag is not specified and the two parameters are set to 0, the icon or cursor is drawn using its own dimensions.
DI_IMAGE
Draw the icon's or cursor's image data onto the device.
DI_MASK
Draw the icon's or cursor's mask data onto the device.
DI_NORMAL
Draw the icon or cursor using both its image and mask, as usual.

Constant Definitions

Const DI_COMPAT = &H4
Const DI_DEFAULTSIZE = &H8
Const DI_IMAGE = &H2
Const DI_MASK = &H1
Const DI_NORMAL = &H3

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

DrawIcon

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