那就用onevent模式了
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)
GUICreate("", 300, 200, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")
$listview = GUICtrlCreateListView(" 1 |2", 5, 5, 290, 190)
For $i = 1 To 10
GUICtrlCreateListViewItem("第" & $i & "行|第二列", $listview)
GUICtrlSetOnEvent(-1, "_test")
Next
GUISetState()
While 1
Sleep(10)
WEnd
Func _test()
MsgBox(0, "", GUICtrlRead(@GUI_CtrlId))
EndFunc ;==>_test
Func _exit()
Exit
EndFunc ;==>_exit
不过我觉得通过焦点来获取挺好的啊
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUICreate("", 300, 200, -1, -1)
$listview = GUICtrlCreateListView(" |", 5, 5, 290, 190)
GUICtrlCreateListViewItem("www.baidu.com", $listview)
GUICtrlCreateListViewItem("www.google.com", $listview)
GUISetState()
Do
Sleep(10)
Until GUIGetMsg() = -3
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iCode
$hWndListView = GUICtrlGetHandle($listview)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam) ; $tagNMHDR - Contains information about a notification message
$hWndFrom = DllStructGetData($tNMHDR, 'hWndFrom')
$iCode = DllStructGetData($tNMHDR, 'Code')
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK ; Sent by a list-view control when user clicks an item with left mouse button
$aHIT = _GUICtrlListView_SubItemHitTest($hWndListView)
If _GUICtrlListView_GetItemText($listview, $aHIT[0]) <> "" Then MsgBox(0, "", _GUICtrlListView_GetItemText($listview, $aHIT[0]))
EndSwitch
EndSwitch
EndFunc ;==>WM_NOTIFY
|