找回密码
 加入
搜索
查看: 1620|回复: 5

怎样做到列表ListView内的全选

[复制链接]
发表于 2009-4-23 23:55:41 | 显示全部楼层 |阅读模式
本帖最后由 gogo023 于 2009-4-24 15:58 编辑

怎么把如下代码内的图标列表里的内容全选,
并用FOR。。TO 按顺序显示出来。
(以下代码借用某位作者的。)
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=C:\Program Files\Autoit3\Aut2Exe\Icons\netscape.ico
#AutoIt3Wrapper_UseAnsi=y
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
 
#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("", 32, 32, $x-50, $y-40)
 
$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)
        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  
发表于 2009-4-24 02:21:23 | 显示全部楼层
去掉风格中的$LVS_SINGLESEL,然后:
_GUICtrlListView_SetItemSelected($List1, -1)
部分选择请查阅_GUICtrlListView_SetItemSelected函数说明。
发表于 2009-5-29 13:35:30 | 显示全部楼层
英文的帮助文档,看不明白!好像不能全选的样子!
发表于 2009-5-29 15:26:53 | 显示全部楼层
sensel 方法可行,不知道楼主有无测试过
发表于 2009-5-30 11:01:57 | 显示全部楼层
没错,我试过是可以的。
发表于 2009-6-21 18:26:36 | 显示全部楼层
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-12 16:44 , Processed in 0.074579 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表