#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListBox.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
$x = 730
$y = 571
$Form1 = GUICreate("Form1", $x, $y, 193, 125, $WS_OVERLAPPEDWINDOW)
$List1 = GUICtrlCreateListView("", 0, 0, $x - 70, $y - 60)
_GUICtrlListView_SetExtendedListViewStyle($List1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
$Button3 = GUICtrlCreateButton("运行", 670, 10, 50, 25)
$Button4 = GUICtrlCreateButton("全选", 670, 40, 50, 25)
$Button5 = GUICtrlCreateButton("反选", 670, 70, 50, 25)
$Menu = GUICtrlCreateContextMenu($List1)
$About = GUICtrlCreateMenuItem("执行", $Menu)
$Refresh = GUICtrlCreateMenuItem("刷新", $Menu)
GUICtrlSetStyle($List1, BitOR($LVS_NOCOLUMNHEADER, $LVS_ICON, $LVS_SORTASCENDING, $LVS_SINGLESEL))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$Image = _GUIImageList_Create(32, 32, 5)
For $i = 1 To 50
_GUIImageList_AddIcon($Image, "c:\WINDOWS\system32\shell32.dll", $i, True)
_GUICtrlListView_SetImageList($List1, $Image, 0)
_GUICtrlListView_AddItem($List1, "第" & $i & "个", $i - 1)
Next
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $About
$Index = _GUICtrlListView_GetSelectedIndices($List1)
If $Index <> "" Then
$L_Name = _GUICtrlListView_GetItemText($List1, Int($Index), 0)
MsgBox(0, "鼠标右键", $Index & "你执行的是 " & $L_Name)
EndIf
Case $Refresh
_GUICtrlListView_Arrange($List1, 2)
Case $GUI_EVENT_MAXIMIZE
_GUICtrlListView_Arrange($List1, 2)
Case $GUI_EVENT_RESTORE
_GUICtrlListView_Arrange($List1, 2)
Case $GUI_EVENT_RESIZED
_GUICtrlListView_Arrange($List1, 2)
Case $Button3
For $i = _GUICtrlListView_GetTopIndex($List1) To _GUICtrlListView_GetCounterPage($List1);列表视图最高可见项的索引 to 可见项索引的总数
$Checked = _GUICtrlListView_GetItemChecked($List1, $i);返回列表视图控件项目的选中状态
If $Checked = 1 Then
MsgBox(266304, "提示", $i)
EndIf
Next
Case $Button4
_GUICtrlListView_SetItemChecked($List1, -1)
Case $Button5
For $i = 0 To _GUICtrlListView_GetItemCount($List1) - 1
If _GUICtrlListView_GetItemChecked($List1, $i) Then
_GUICtrlListView_SetItemChecked($List1, $i, False)
Else
_GUICtrlListView_SetItemChecked($List1, $i, True)
EndIf
Next
EndSwitch
WEnd
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $Menu
$hWndListView = $List1
If Not IsHWnd($List1) Then $hWndListView = GUICtrlGetHandle($List1)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $NM_DBLCLK ; 响应 List1 范围内的双击
$Index = _GUICtrlListView_GetSelectedIndices($hWndListView)
If $Index <> "" Then
$L_Name = _GUICtrlListView_GetItemText($hWndListView, $Index)
MsgBox(0, "响应双击", "你选择的是 " & $L_Name)
EndIf
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY