#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Global $aItem, $input[5]
GUICreate("ListView Get Item Text Array 简单应用", 400, 320)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$ListView1 = GUICtrlCreateListView("col1|col2|col3|col4", 2, 2, 394, 168)
GUICtrlCreateListViewItem("张学友1|刘德华|黎明|郭富城", $ListView1)
GUICtrlCreateListViewItem("张飞1|赵云|关羽|刘备", $ListView1)
GUICtrlCreateListViewItem("张学友2|刘德华|黎明|郭富城", $ListView1)
GUICtrlCreateListViewItem("张飞2|赵云|关羽|刘备", $ListView1)
GUICtrlCreateListViewItem("张学友3|刘德华|黎明|郭富城", $ListView1)
GUICtrlCreateListViewItem("张飞3|赵云|关羽|刘备", $ListView1)
$label = GUICtrlCreateLabel("搜索内容:", 25, 174, 100, 25)
$input[0] = GUICtrlCreateInput("张飞", 80, 170, 100, 25)
$Button = GUICtrlCreateButton('开始搜索', 200, 170, 90, 25)
$input[1] = GUICtrlCreateInput("", 2, 200, 100, 25)
$input[2] = GUICtrlCreateInput("", 2, 230, 100, 25)
$input[3] = GUICtrlCreateInput("", 2, 260, 100, 25)
$input[4] = GUICtrlCreateInput("", 2, 290, 100, 25)
GUISetState()
$n = 0
While 1
$Msg = GUIGetMsg()
Select
Case $Msg = $GUI_EVENT_CLOSE
Exit
Case $Msg = $Button
$Index = _GUICtrlListView_FindInText($ListView1, GUICtrlRead($input[0]), $n)
If $Index < $n Then
MsgBox(0, 0, '搜索完毕')
$n = 0
Else
$n = $Index
setinput()
EndIf
EndSelect
WEnd
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
;~ ...
Case $NM_DBLCLK ; 双击
$Index = _GUICtrlListView_GetSelectedIndices($ListView1); 获取被选的索引
If Not StringLen($Index) Then; 判断是否选定Item
MsgBox(0, "", "未选定")
Return
EndIf
setinput()
Case $NM_RCLICK ; 右击
;~ ...
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func setinput()
$aItem = _GUICtrlListView_GetItemTextArray($ListView1, Number($Index))
For $i = 1 To $aItem[0]
GUICtrlSetData($input[$i], $aItem[$i])
Next
EndFunc ;==>setinput
关键: