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
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.
If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a non-zero value.
None.
Const DI_COMPAT = &H4
Const DI_DEFAULTSIZE = &H8
Const DI_IMAGE = &H2
Const DI_MASK = &H1
Const DI_NORMAL = &H3
' 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/d/drawiconex.html