Function Reference


Replaces an image with an icon or cursor

#include <GuiImageList.au3>
_GUIImageList_ReplaceIcon ( $hWnd, $iIndex, $hIcon )


$hWnd Handle to the imagelist
$iIndex Index of the image to replace. If -1, the function appends the image to the end of the list.
$hIcon Handle to the icon or cursor that contains the bitmap and mask for the new image

Return Value

Success: the index of the image.
Failure: -1.


Because the system does not save $hIcon you can destroy it after the function returns if the icon or cursor was created by the CreateIcon function.
You do not need to destroy $hIcon if it was loaded by the LoadIcon function the system automatically frees an icon resource when it is no longer needed.


#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WinAPIIcons.au3>
#include <WindowsConstants.au3>


Func Example()
        Local $idListview, $hImage
        Local $sWow64 = ""
        If @AutoItX64 Then $sWow64 = "\Wow6432Node"
        Local $sAutoItDir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE" & $sWow64 & "\AutoIt v3\AutoIt", "InstallDir")

        GUICreate("ImageList AddIcon", 490, 300)
        $idListview = GUICtrlCreateListView("", 2, 2, 484, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))

        ; Create an image list with images
        $hImage = _GUIImageList_Create(11, 11)
        AddIcon($hImage, $sAutoItDir & "\Icons\au3.ico")
        AddIcon($hImage, $sAutoItDir & "\Icons\au3script_v9.ico")
        AddIcon($hImage, $sAutoItDir & "\Icons\au3script_v10.ico")
        AddIcon($hImage, $sAutoItDir & "\Icons\au3script_v11.ico")
        _GUICtrlListView_SetImageList($idListview, $hImage, 1)

        ; Add columns
        _GUICtrlListView_AddColumn($idListview, "Column 1", 100, 0, 0)
        _GUICtrlListView_AddColumn($idListview, "Column 2", 100, 1, 1)
        _GUICtrlListView_AddColumn($idListview, "Column 3", 100, 2, 2)
        _GUICtrlListView_AddColumn($idListview, "Column 4", 100, 1, 3)
        _GUICtrlListView_AddColumn($idListview, "Column 5", 100)

        ; Loop until the user exits.
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; This is the long way to add an icon. Use _GUIImageList_AddIcon instead
Func AddIcon($hWnd, $sFile, $iIndex = 0)
        Local $tIcon, $hIcon

        $tIcon = DllStructCreate("int Icon")
        _WinAPI_ExtractIconEx($sFile, $iIndex, 0, $tIcon, 1)
        $hIcon = DllStructGetData($tIcon, "Icon")
        _GUIImageList_ReplaceIcon($hWnd, -1, $hIcon)
EndFunc   ;==>AddIcon