#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
Global $hListView,$count_select,$hListView,$hLabel
$count_select=0
GUICreate("ListView Click Item", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle(-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
$hLabel = GUICtrlCreateLabel("", 2, 275, 394, 15)
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 200)
_GUICtrlListView_InsertColumn($hListView, 0, "Column 2", 150)
For $i=1 To 20
_GUICtrlListView_AddItem($hListView, "Row "&$i&": Col 1", $i)
Next
GUICtrlSetData($hLabel,"已选定"&$count_select[0]&"个item")
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_CLICK
$Index = _GUICtrlListView_GetSelectionMark($hListView)
If _GUICtrlListView_GetItemFocused($hListView,$Index)=True Then
$check=_GUICtrlListView_GetItemChecked($hListView,$Index)
If $check=True Then
_GUICtrlListView_SetItemChecked($hListView,$Index,False)
$count_select-=1
Else
_GUICtrlListView_SetItemChecked($hListView,$Index)
$count_select+=1
EndIf
EndIf
GUICtrlSetData($hLabel,"已选定"&$count_select&"个item")
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc
这段代码需要实现的是当鼠标单击item时,如果复选框状态为UnChecked状态,则复选框状态更改为Checked,计数器+1,如果复选框状态为Checked,则更改为UnChecked,计数器-1,但是在实际运行过程中发现,鼠标位置在复选框处时点击,计数器的值会更改,但是复选框状态有时不能正常转换...