Function Reference


_GUICtrlButton_SetImageList

Assigns an image list to a button control

#include <GuiButton.au3>
_GUICtrlButton_SetImageList ( $hWnd, $hImage [, $iAlign = 0 [, $iLeft = 1 [, $iTop = 1 [, $iRight = 1 [, $iBottom = 1]]]]] )

Parameters

$hWnd Control ID/Handle to the control
$hImage A handle to the image list.
Should contain either a single image to be used for all states or individual images for each state listed in the following:
    1 - Normal
    2 - Hot
    3 - Pressed
    4 - Disabled
    5 - Defaulted
    6 - Stylus Hot (tablet computers only)
$iAlign [optional] Specifies the alignment to use. This parameter can be one of the following values:
    0 - Align the image with the left margin.
    1 - Align the image with the right margin.
    2 - Align the image with the top margin.
    3 - Align the image with the bottom margin.
    4 - Center the image.
$iLeft [optional] Left margin of the icon
$iTop [optional] Top margin of the icon
$iRight [optional] Right margin of the icon
$iBottom [optional] Bottom margin of the icon

Return Value

Success: True.
Failure: False.

Remarks

Image list with multiple images will only show the images other than the 1st image when Themes is being used.

Related

_GUICtrlButton_GetImageList

See Also

Search BCM_SETIMAGELIST in MSDN Library.

Example

Example 1

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Global $g_idMemo

Example()

Func Example()
        GUICreate("Button Get/Set ImageList (v" & @AutoItVersion & ")", 510, 400)
        $g_idMemo = GUICtrlCreateEdit("", 119, 10, 376, 374, $WS_VSCROLL)
        GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
        GUISetState(@SW_SHOW)

        Local $hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
        For $x = 6 To 11
                _GUIImageList_AddIcon($hImage, "shell32.dll", $x, True)
        Next

        Local $a_idBtn[6]
        $a_idBtn[0] = GUICtrlCreateButton("Button1", 10, 10, 90, 50)
        _GUICtrlButton_SetImageList($a_idBtn[0], $hImage)

        Local $y = 70, $iIcon = 125
        For $x = 1 To 5
                $a_idBtn[$x] = GUICtrlCreateButton("Button" & $x + 1, 10, $y, 90, 50)
                _GUICtrlButton_SetImageList($a_idBtn[$x], _GetImageListHandle("shell32.dll", $iIcon + $x, True), $x)
                $y += 60
        Next

        Local $aImageListInfo
        For $x = 0 To 5
                $aImageListInfo = _GUICtrlButton_GetImageList($a_idBtn[$x])
                MemoWrite("Button" & $x + 1 & " Imagelist Info" & @CRLF & "--------------------------------")
                MemoWrite("Image list handle........: " & $aImageListInfo[0])
                MemoWrite("Left margin of the icon..: " & $aImageListInfo[1])
                MemoWrite("Top margin of the icon...: " & $aImageListInfo[2])
                MemoWrite("Right margin of the icon.: " & $aImageListInfo[3])
                MemoWrite("Bottom margin of the icon: " & $aImageListInfo[4])
                MemoWrite("Alignment: " & _ExplainAlignment($aImageListInfo[5]))
                MemoWrite("--------------------------------" & @CRLF)
        Next

        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd

        Exit
EndFunc   ;==>Example

; Write a line to the memo control
Func MemoWrite($sMessage)
        GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; using image list to set 1 image and have text on button
Func _GetImageListHandle($sFile, $nIconID = 0, $bLarge = False)
        Local $iSize = 16
        If $bLarge Then $iSize = 32

        Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImage, $sFile)
        Else
                _GUIImageList_AddIcon($hImage, $sFile, $nIconID, $bLarge)
        EndIf
        Return $hImage
EndFunc   ;==>_GetImageListHandle

Func _ExplainAlignment($iAlign)
        Switch $iAlign
                Case 0
                        Return "Image aligned with the left margin."
                Case 1
                        Return "Image aligned with the right margin."
                Case 2
                        Return "Image aligned with the top margin."
                Case 3
                        Return "Image aligned with the bottom margin."
                Case 4
                        Return "Image centered."
        EndSwitch
EndFunc   ;==>_ExplainAlignment

Example 2

#include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>

Example()

Func Example()
        GUICreate("Button Get/Set ImageList (v" & @AutoItVersion & ")", 510, 400)
        GUISetState(@SW_SHOW)

        Local $hImage = _GUIImageList_Create(32, 32, 5, 3, 6)
        For $x = 6 To 11
                _GUIImageList_AddIcon($hImage, "shell32.dll", $x, True)
        Next

        Local $hImageSmall = _GUIImageList_Create(16, 16, 5, 3, 6)
        For $x = 6 To 11
                _GUIImageList_AddIcon($hImageSmall, "shell32.dll", $x)
        Next

        Local $a_idBtn[6]
        $a_idBtn[0] = GUICtrlCreateButton("Button1", 10, 10, 90, 50)
        _GUICtrlButton_SetImageList($a_idBtn[0], $hImage)

        Local $a_idRdo[6]
        $a_idRdo[0] = GUICtrlCreateRadio("Radio Button1", 120, 10, 120, 25)
        _GUICtrlButton_SetImageList($a_idRdo[0], $hImageSmall)

        Local $a_idChk[6]
        $a_idChk[0] = GUICtrlCreateCheckbox("Check Button1", 260, 10, 120, 25)
        _GUICtrlButton_SetImageList($a_idChk[0], $hImageSmall)

        Local $y = 70, $iIcon = 125
        For $x = 1 To 5
                $a_idBtn[$x] = GUICtrlCreateButton("Button" & $x + 1, 10, $y, 90, 50)
                _GUICtrlButton_SetImageList($a_idBtn[$x], _GetImageListHandle("shell32.dll", $iIcon + $x, True), $x)
                $a_idRdo[$x] = GUICtrlCreateRadio("Radio Button" & $x + 1, 120, $y, 120, 25)
                _GUICtrlButton_SetImageList($a_idRdo[$x], _GetImageListHandle("shell32.dll", $iIcon + $x), $x)
                $a_idChk[$x] = GUICtrlCreateCheckbox("Check Button" & $x + 1, 260, $y, 120, 25)
                _GUICtrlButton_SetImageList($a_idChk[$x], _GetImageListHandle("shell32.dll", $iIcon + $x), $x)
                $y += 60
        Next

        While 1
                Switch GUIGetMsg()
                        Case $GUI_EVENT_CLOSE
                                ExitLoop
                EndSwitch
        WEnd

        Exit
EndFunc   ;==>Example

; using image list to set 1 image and have text on button
Func _GetImageListHandle($sFile, $nIconID = 0, $bLarge = False)
        Local $iSize = 16
        If $bLarge Then $iSize = 32

        Local $hImage = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImage, $sFile)
        Else
                _GUIImageList_AddIcon($hImage, $sFile, $nIconID, $bLarge)
        EndIf
        Return $hImage
EndFunc   ;==>_GetImageListHandle