#include <Array.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
GUICreate("ListView Add Array", 800, 300)
$idListview = GUICtrlCreateListView("", 2, 2, 394, 268)
GUISetState(@SW_SHOW)
_GUICtrlListView_AddColumn($idListview, "Tester", 100)
_GUICtrlListView_AddColumn($idListview, "Test Item", 100)
_GUICtrlListView_AddColumn($idListview, "BMC IP", 100)
_GUICtrlListView_AddColumn($idListview, "Count", 100)
_GUICtrlListView_AddColumn($idListview, "Last Record Time", 100)
_GUICtrlListView_SetItemCount($idListview, 5000)
_add_lv_items()
AdlibRegister('_add_lv_items', 5000); 5秒刷新数据
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Func _add_lv_items()
Local $path, $aFileList, $aNewList[1][2]
$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")
If IsArray($aFileList) Then
ReDim $aNewList[UBound($aFileList)][5] ;;;[Col count]
For $i = 0 To UBound($aFileList) - 1 Step 1
$aNewList[$i][0] = $aFileList[$i]
$aNewList[$i][1] = FileReadLine($aFileList[$i], 1)
$aNewList[$i][2] = FileReadLine($aFileList[$i], 2)
$aNewList[$i][3] = FileReadLine($aFileList[$i], 3)
$aNewList[$i][4] = FileReadLine($aFileList[$i], 4)
Next
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($idListview))
_GUICtrlListView_AddArray($idListview, $aNewList)
EndIf
EndFunc
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = GUICtrlGetHandle($idListview)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK ;鼠标双击
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
$Index= DllStructGetData($tInfo, "Index")
MsgBox(0, '', _GUICtrlListView_GetItemTextString($hWndListView, $Index))
EndSwitch
EndSwitch
EndFunc