在控件内添加新列
#include <GuiListView.au3>
_GUICtrlListView_AddColumn($hWnd, $sText [, $iWidth = 50 [, $iAlign = -1 [, $iImage = -1 [, $fOnRight = False]]]])
$hWnd | 控件的控件ID/句柄 |
$sText | 列标题文本 |
$iWidth | [可选参数] 列像素宽度 |
$iAlign | [可选参数]列标题和列项目文本对齐方式: 0 - 左对齐 1 - 右对齐 2 - 居中对齐 |
$iImage | [可选参数] 图像列表中的图像 0 基索引 |
$fOnRight | [可选参数] 如为 True, 则列图像显示在文字右侧 |
成功: | 返回新列的索引 |
失败: | 返回 -1 |
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
$Debug_LV = False ; 检查传递给 ListView 函数的类名, 设置为True并输出到一个控件的句柄,用于检查它是否工作
_Main()
Func _Main()
Local $hImage, $hListView
; 创建 GUI
GUICreate("ListView Add Column", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
; 启用扩展控件样式
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState()
; 加载图像
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap(GUICtrlGetHandle($hListView), 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($hListView, $hImage, 1)
; 添加列
_GUICtrlListView_AddColumn($hListView, "Column 1", 100)
_GUICtrlListView_AddColumn($hListView, "Column 2", 100)
_GUICtrlListView_AddColumn($hListView, "Column 3", 100)
; 添加项目
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1, 2)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)
; 循环直到用户退出
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>_Main