找回密码
 加入
搜索
查看: 2887|回复: 6

[AU3基础] ListView 如何判断复选框是否选中

    [复制链接]
发表于 2017-5-11 01:36:02 | 显示全部楼层 |阅读模式
请教各位大侠,怎样才能实现未选中复选框停止执行
#RequireAdmin
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiStatusBar.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>

Global $Wimlib="F:\PETOOLS\镜像工具\wimlib\wimlib-imagex.exe"
Global $wimdism=@WindowsDir&"\system32\dism.exe"
$Form_main = GUICreate("", 530, 520, -1, -1)

Global $Edit = GUICtrlCreateEdit("",20, 445, 490, 50)
GUICtrlSetData(-1, "<返回值显示区域>")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Local $idListview = GUICtrlCreateListView("", 50, 50, 430, 350,-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES,$LVS_EX_CHECKBOXES))
_GUICtrlListView_AddColumn($idListview, "", 40, 2)
_GUICtrlListView_AddColumn($idListview, " 映像文件", 160, 2)
_GUICtrlListView_AddColumn($idListview, "卷号", 40, 2)
_GUICtrlListView_AddColumn($idListview, " 名称", 140, 2)
_GUICtrlListView_AddColumn($idListview, "描述", 50, 2)
_GUICtrlListView_AddColumn($idListview, "系统标志", 50, 2)
$Handle = GUICtrlGetHandle(-1)
$Button1 = GUICtrlCreateButton("添加文件", 208, 402, 73, 33)
$Button2 = GUICtrlCreateButton("导出文件", 308, 402, 73, 33)
GUISetState(@SW_SHOW, $Form_main)

;GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                        Case -3
                            Exit
                        Case $Button1
                                $addfile = FileOpenDialog("请选择一个映像文件", "", "wim文件 (*.wim)", 1, "", $Form_main)
                                ;MsgBox(0,"",$addfile)
                                disminfo()
                        
                        Case $Button2
                                ab()        
                        
                                
                                


                EndSwitch
WEnd
Func disminfo()
        Local $sMountInfo = @ScriptDir&"\MountInfo.txt"
        FileDelete($sMountInfo)
        RunWait(@ComSpec & ' /C '  & $wimdism & ' /Get-WimInfo /WimFile:'&$addfile&' > '& $sMountInfo, @WindowsDir & '\system32', @SW_HIDE)
        ;RunWait(@ComSpec & ' /C '  & $Wimlib & ' info '&$addfile&' > '& $sMountInfo, @WindowsDir & '\system32', @SW_HIDE)
         $MountTxt = FileRead($sMountInfo)
        Local $Index = StringRegExp($MountTxt, '索引:(\V+)', 3)
        Local $Filepath = StringRegExp($MountTxt, '映像的详细信息: (\V+)', 3)
        Local $imagename=StringRegExp($MountTxt, '名称:(\V+)', 3)
        Local $imageDescription=StringRegExp($MountTxt, '描述: (\V+)', 3)
        ;Local $imageFlags=StringRegExp($MountTxt, 'Flags: (\V+)', 3)
        For $i = 0 To UBound($imagename )-1        
                GUICtrlCreateListViewItem(""&"|"& $Filepath[0] &"|"&$Index[$i]&"|"&$imagename[$i]&"|"&$imageDescription[$i],$idListview)

        Next
        
EndFunc
Func ab()
GUICtrlSetState($Button1        ,$GUI_DISABLE)
GUICtrlSetState($Button2        ,$GUI_DISABLE)
Local $bool = False
If  _GUICtrlListView_GetItemCount($idListview)=0 Then
        MsgBox(0,"","还没添加文件,不能继续!!!")
        GUICtrlSetState($Edit, $GUI_ENABLE)
        GUICtrlSetState($Button1,$GUI_ENABLE)
        GUICtrlSetState($Button2,$GUI_ENABLE)
ElseIf _GUICtrlListView_GetItemCount($idListview)>=1 Then
                 
        $WimFile =""
        $ImageID=""
        $ImageName=""
        For $I = 0 To _GUICtrlListView_GetItemCount($idListview)-1
            If _GUICtrlListView_GetItemChecked($idListview,$i)=False Then  ;如此处加入未选中判断,但要点很多次确定,怎样才能实现未选中停止执行
                        MsgBox(0,"","没有选择,不能继续")
                ElseIf _GUICtrlListView_GetItemChecked($idListview,$i)=True Then
                        
                        $WimFile &=  _GUICtrlListView_GetItemText($idListview, $i,1)&@CRLF
                        $ImageID &=_GUICtrlListView_GetItemText($idListview, $i,2)&@CRLF
                        $ImageName&=_GUICtrlListView_GetItemText($idListview, $i,3)&@CRLF
                
            EndIf 
        Next
        Local $expropath="e:\test.wim"
        Local $aData=StringRegExp($WimFile,'(?<grp0>[^\n]+)',3)
        Local $id=StringRegExp($ImageID,'(?<grp0>[^\D]+)',3)
        For $i=0 To UBound($aData)-1
                ToolTip(" 正在合并 " & ($aData)[$i] &"--------"&$id[$i]&"号卷映像 ", @DesktopWidth-320, @DesktopHeight-100)
                Local $exportwim=Run(@ComSpec & ' /C ' & $wimdism& ' /Export-Image /SourceImageFile:' & $aData[$i] & ' /SourceIndex:'& $id[$i] & ' /DestinationImageFile:'&$expropath, @WindowsDir & '\system32',@SW_HIDE, $STDOUT_CHILD);dism导出wim映像
                While 1
                        $line = StdoutRead($exportwim)
                        If @error Then ExitLoop
                        GUICtrlSetData($Edit, $line, -1)
                Wend
        Next
        MsgBox(0,"","合并完成!!!",5)
        GUICtrlSetState($Edit, $GUI_ENABLE)
        GUICtrlSetState($Button1,$GUI_ENABLE)
        GUICtrlSetState($Button2,$GUI_ENABLE)
EndIf

        
EndFunc
发表于 2017-5-11 09:48:55 | 显示全部楼层
回复 4# bnwangp

打勾  然後按下檢查看看

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
 
;Opt('MustDeclareVars', 1)
 
Global $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work
 

        Local $hImage, $hListView, $exStyles = BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES, $lvs_ex_checkboxes)
        
        GUICreate("ListView Get Item Image", 400, 300)
        $hListView = GUICtrlCreateListView("", 2, 2, 394, 268)
        _GUICtrlListView_SetExtendedListViewStyle($hListView, $exStyles)
                
                
                $Bn1 = GUICtrlCreateButton("檢查第一個是否打勾", 10, 275, 200,20)
                
        GUISetState()
 
        ; Load images
        $hImage = _GUIImageList_Create()
        _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
        _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
        _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
        _GUICtrlListView_SetImageList($hListView, $hImage, 1)
 
        ; Add columns
        _GUICtrlListView_AddColumn($hListView, "Column 1", 100)
        _GUICtrlListView_AddColumn($hListView, "Column 2", 100)
        _GUICtrlListView_AddColumn($hListView, "Column 3", 100)
 
        ; Add items
        _GUICtrlListView_AddItem($hListView, "", 0)
        _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1, 1)
        _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2, 2)
                
        ;_GUICtrlListView_AddItem($hListView, "", 1)
        ;_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1, 2)
        ;_GUICtrlListView_AddItem($hListView, "", 2)
 
        ; Set item 1, subitem 1 image
        _GUICtrlListView_SetItemImage($hListView, 1, 1, 1)
                
                
        ;MsgBox(4160, "Information", "Item 1, SubItem 1 Image: " & _GUICtrlListView_GetItemImage($hListView, 1, 1))
 
        ; Loop until user exits
 While 1
       ; $nMsg = GUIGetMsg()
        Switch GUIGetMsg()
                Case -3
                        Exit
                                Case $Bn1
                                        If _GUICtrlListView_GetItemChecked($hListView, 0)=0  Then
                                                 MsgBox(0,"","第一個項目 沒有打勾")
                                        Else
                                   MsgBox(0,"","第一個項目 打勾了")                
                                   EndIf
        EndSwitch
WEnd
        
        
发表于 2017-5-11 03:09:04 | 显示全部楼层
回复 1# bnwangp

有點好玩
【怎样才能实现未选中复选框停止执行 】  

程式 一執行的時候  複選框 一定沒被選中   由於上面的邏輯  所以  就停止執行...

等同 不要執行 程式  就達到要求了...
发表于 2017-5-11 03:17:46 | 显示全部楼层
回复 1# bnwangp


    GUICtrlRead
讀取控制項的狀態或資料.


GUICtrlRead ( 控制項ID [, 高級] )



參 數
控制項ID 由 GUICtrlCreate... 函數返回的控制項識別字.
高級 [可選參數] 返回控制項的擴展資訊.
0 = (預設) 返回控制項的狀態或者資料.
1 = 返回控制項的擴展資訊 (見備註).



返 回 值
成功: 返回值因控制項類型的不同而不同(請看下表).
失敗: 返回 0.
控制項類型 返回值
Checkbox(核取方塊), Radio(單選框) 選擇狀態, 請參考. 狀態表
Combo(下拉式列示方塊), List(清單方塊) 選中項目的值
Input(輸入框), Edit(編輯方塊) 輸入的文本
Button(按鈕) 顯示的文本
Date(日期) 選擇的日期, 格式由區域設置定義
Progress(進度條) 當前進度百分比
Slider(滑動條) 當前值
Tab(標籤頁控制項) 選中的標籤頁編號; 或依據 "高級" 參數值返回標籤專案的控制項 ID.
Menu, MenuItemMenu(菜單), MenuItem(功能表項目目) 功能表/專案的狀態. 請參考 狀態表  
TreeView(樹樹圖) TreeView 選中專案的控制項識別字
TreeViewItem(樹狀檢視專案) 樹狀檢視專案的狀態
ListView(列表視圖) ListView 選中專案的控制項識別字. 0 表示沒有專案被選中
Dummy(虛擬控制項) 由 GUICtrlSendToDummy 獲 GUICtrlSetData設置的值
 楼主| 发表于 2017-5-11 03:40:03 | 显示全部楼层
列表Listview中的复选框控件我用GUICtrlRead读取不到它的值,不知为何??本来这句If _GUICtrlListView_GetItemChecked($idListview,$i)=False Then应该用GUICtrlRead读取,但就是GUICtrlRead读取读取不到,我才换成了_GUICtrlListView_GetItemChecked,请高手指点
发表于 2017-5-17 21:13:59 | 显示全部楼层
是很有用的
 楼主| 发表于 2017-5-27 08:35:01 | 显示全部楼层
回复 5# kk_lee69


    谢谢,我已解决了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-19 07:37 , Processed in 0.079570 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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