如何给ListView添加鼠标的点击事件?急
是指点击某行后,直接运行函数的,而不是通过获取焦点间接实现的,拜谢了 那就用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) <> "" Then MsgBox(0, "", _GUICtrlListView_GetItemText($listview, $aHIT))
EndSwitch
EndSwitch
EndFunc ;==>WM_NOTIFY
回复 2# zch11230
膜拜高淫,看了好久的ListView鼠标点击代码,还是看不懂... 回复 2# zch11230
先谢谢了,明天测试下 回复 2# zch11230
双击呢,有办法不? 回复 5# zuiyi
难道都不看帮助的吗? 本帖最后由 xms77 于 2012-10-21 16:56 编辑
]回复 5# zuiyi
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
Local $Index,$itemText,$iMachineId,$answer
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $hListView
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
;...
Case $NM_DBLCLK ; 双击
;...
Case $NM_RCLICK ; 右击
;...
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY 回复 7# xms77
谢谢了
页:
[1]