#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
AutoItSetOption("GUIOnEventMode", 1)
; 创建 GUI
GUICreate("添加列表视图子项", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "funcGUISetOnEvent")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;监听事件,要紧跟在控件后面(事件类型,回调函数)
$hListView = GUICtrlCreateListView("列1 |列2 |列3 |", 2, 2, 394, 268)
; 添加项目
_GUICtrlListView_InsertItem($hListView, "第一此插入行", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "一2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "一3", 2)
_GUICtrlListView_InsertItem($hListView, "第二次插入行", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "2-2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "2-3", 2)
_GUICtrlListView_InsertItem($hListView, "第三次插入", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "三-1", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "三-2", 2)
GUISetState(@SW_SHOW)
While 1
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
Local $hWndFrom = DllStructGetData($tNMHDR, 2)
Local $iCode = DllStructGetData($tNMHDR, 3)
Switch $hWndFrom
Case $hListView
Switch $iCode
Case $NM_DBLCLK
$Index = _GUICtrlListView_GetSelectedIndices($hListView) ;行标示符
$L_Name = _GUICtrlListView_GetItemTextString($hListView, Number($Index)) ;整行内容。_GUICtrlListView_GetItemText为指定行第一个单元格内容
;$lsid = GUICtrlRead($hListView) ;选中行的标识符,读不到
;$strL = GUICtrlRead($Index) ;整行文本内容,读不到
MsgBox(0, "", "选择的行标示符:" & $Index & @CRLF & "整行文本:" & $L_Name)
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
Func funcGUISetOnEvent()
Exit
EndFunc