函数参考


_GUIImageList_Add

添加图像到图像列表

#Include <GuiImageList.au3>
_GUIImageList_Add($hWnd, $hImage[, $hMask=0])

参数

$hWnd 控件句柄
$hImage 包含图像的位图句柄,从位图宽度推断图像数量.
$hMask [可选参数] 包含蒙板的位图句柄

返回值

成功: 返回第一个图像的索引
失败: 返回 -1

注意/说明

 函数将位图拷贝到内部数据结构.
 函数返回后,一定要使用 _WinAPI_DeleteObject 函数删除 $hImage 和 $hMask.

相关

_GUIImageList_AddMasked, _GUIImageList_AddBitmap, _GUIImageList_AddIcon

示例/演示


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

_Main()

Func _Main()
    Local $listview, $hImage
    Local $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)

    GUICreate("ImageList Add", 400, 300)
    $listview = GUICtrlCreateListView("", 2, 2, 394, 268, BitOR($LVS_SHOWSELALWAYS, $LVS_NOSORTHEADER, $LVS_REPORT))
    _GUICtrlListView_SetExtendedListViewStyle($listview, $exStyles)
    GUISetState()

    ; 加载图像
    $hImage = _GUIImageList_Create(11, 11)
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 11, 11))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 11, 11))
    _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x0000FF, 11, 11))
    _GUICtrlListView_SetImageList($listview, $hImage, 1)

    ; 添加列
    _GUICtrlListView_AddColumn($listview, "Items", 120)

    ; 添加项目
    _GUICtrlListView_AddItem($listview, "Item 1", 0)
    _GUICtrlListView_AddItem($listview, "Item 2", 1)
    _GUICtrlListView_AddItem($listview, "Item 3", 2)

    ; 循环直到用户退出
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    GUIDelete()
EndFunc   ;==>_Main