函数参考


_GUICtrlButton_GetImageList

获取图像列表对按钮控件分配状态的数组

#include <GuiButton.au3>
_GUICtrlButton_GetImageList($hWnd)

参数

$hWnd 控件的控件ID/句柄

返回值

返回包含下列各项的数组:
    [0] - 图像列表句柄
    [1] - 图标左页边空白
    [2] - 图标顶页边空白
    [3] - 图标右页边空白
    [4] - 图标底页边空白
    [5] - 确定对齐方式。将会是下列数值之一:
    0 - 图像左对齐.
    1 - 图像右对齐.
    2 - 图像顶对齐.
    3 - 图像底对齐.
    4 - 图像居中.

注意/说明

最低操作系统: Windows XP.

相关

_GUICtrlButton_SetImageList

详情参考

在MSDN中搜索


示例/演示


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

Global $iMemo

_Main()

Func _Main()
    Local $hImage, $y = 70, $iIcon = 125, $btn[6], $aImageListInfo

    GUICreate("Buttons", 510, 400)
    $iMemo = GUICtrlCreateEdit("", 119, 10, 376, 374, $WS_VSCROLL)
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    GUISetState()

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

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


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


    For $x = 0 To 5
        $aImageListInfo = _GUICtrlButton_GetImageList($btn[$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   ;==>_Main

; 写入一行到 memo 控件
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc   ;==>MemoWrite

; 使用图像列表在按钮上设置一个图像并显示文本
Func _GetImageListHandle($sFile, $nIconID = 0, $fLarge = False)
    Local $iSize = 16
    If $fLarge 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, $fLarge)
    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