本帖最后由 blue_dvd 于 2012-11-18 22:50 编辑
想要效果
主要是统计用户点击选择了多少个项目?
代码如下#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
GUICreate("ListView Click Item", 400, 300)
$hListView = GUICtrlCreateListView("", 2, 2, 394, 268, "", $LVS_EX_FULLROWSELECT+$LVS_EX_CHECKBOXES)
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 200)
_GUICtrlListView_InsertColumn($hListView, 0, "Column 2", 150)
$hLabel = GUICtrlCreateLabel("已选定0个item", 2, 275, 394, 15)
GUISetState()
For $i = 1 To 20
GUICtrlCreateListViewItem("Row "&$i&": Col 1", $hListView)
Next
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY') ;注册侦测用户是否选择
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
GUIDelete()
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $tNMHDR, $hWndFrom, $iCode
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($HListView)
$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
Local $aHit = _GUICtrlListView_HitTest($hListView)
If $aHit[0]<>-1 And _GUICtrlListView_GetItemChecked($hListView,$aHit[0])=True Then
_GUICtrlListView_SetItemChecked($hListView,$aHit[0])
_GUICtrlListView_SetItemSelected($hListView, $aHit[0],True)
ElseIf $aHit[0]<>-1 And _GUICtrlListView_GetItemChecked($hListView,$aHit[0])=False Then
_GUICtrlListView_SetItemChecked($hListView,$aHit[0],False)
_GUICtrlListView_SetItemSelected($hListView, $aHit[0],False)
EndIf
GUICtrlSetData($hLabel, "共选定项目为"&_GUICtrlListView_GetSelectedCount($hListView))
EndSwitch
EndSwitch
EndFunc
总会出错,不知道什原因?代码比较幼稚,请各位不要笑的太厉害!
解决方法在8楼! |