找回密码
 加入
搜索
查看: 2391|回复: 7

[AU3基础] 求判断单选,然后在反选,反选后的问题 附源码

  [复制链接]
发表于 2011-12-28 01:31:32 | 显示全部楼层 |阅读模式
本帖最后由 fengzishao 于 2011-12-28 11:52 编辑

因为是读取SETUP.INI的配置,后续可能还会再增加配置文件,

现在做到全选的效果:全部选中,反选的效果:全部取消或全部选中,

如果单击选择一个,在点击反选,就会全选。已选中的没有取消掉

图1如下:


图2


图3


源码如下:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form= sljowjkjafojnnn klhdjljlj faffas fmaa ska


Dim $hSitem[30], $Line, $list, $Name, $New, $File, $File1, $TreeView1, $hTreeview, $hSitem1

Global $iStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$Form1 = GUICreate("网卡PNP工具", 501, 371, 192, 114)
$Group2 = GUICtrlCreateGroup("", 0, 318, 500, 7)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\123.jpg", 0, -10, 500, 69)
$Group1 = GUICtrlCreateGroup("", 0, -8, 500, 70)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$hTreeview = GUICtrlCreateTreeView(16, 88, 473, 215, $iStyle, $WS_EX_CLIENTEDGE)
$hFitem01 = GUICtrlCreateTreeViewItem("网卡驱动程序", $hTreeview)

Local $num = 2
For $i = 1 To 25
        $File = FileOpen(@ScriptDir & "\setup.ini")
        $File = FileReadLine($File, $num)
        If $File = "" Then Exit
        $Name = StringReplace($File, 'NIC' & $num - 1 & '=', "", 0)
        ;MsgBox(0,"提示",$name)
        FileClose($File)
        $num = $num + 1
        $Name = IniRead(@ScriptDir & "\setup.ini", $Name, "name", "")
        $hSitem[$i] = GUICtrlCreateTreeViewItem($Name, $hFitem01)
Next

$Label1 = GUICtrlCreateLabel("请选择对应网卡驱动", 24, 72, 112, 17)
$Button1 = GUICtrlCreateButton("全选", 58, 333, 89, 33)
$Button2 = GUICtrlCreateButton("反选", 168, 333, 89, 33)
$Button3 = GUICtrlCreateButton("开始PNP", 280, 333, 89, 33)
$Button4 = GUICtrlCreateButton("退出", 392, 333, 89, 33)
GUICtrlSetState($hFitem01, $GUI_EXPAND)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $hFitem01
                        If BitAND(GUICtrlRead($hFitem01), $GUI_CHECKED) Then
                                For $i = 1 To 25
                                        GUICtrlSetState($hSitem[$i], $GUI_CHECKED)
                                Next
                        ElseIf BitAND(GUICtrlRead($hFitem01), $GUI_UNCHECKED) Then
                                For $i = 1 To 25
                                        GUICtrlSetState($hSitem[$i], $GUI_UNCHECKED)
                                Next
                        EndIf
                Case $Button1 ;全选
                       
                        GUICtrlSetState($hFitem01, $GUI_CHECKED)
                        For $i = 1 To 25
                                GUICtrlSetState($hSitem[$i], $GUI_CHECKED)
                        Next

                Case $Button2 ;反选
                        If BitAND(GUICtrlRead($hFitem01), $GUI_CHECKED) Then
                                GUICtrlSetState($hFitem01, $GUI_UNCHECKED)
                                For $i = 1 To 25
                                        GUICtrlSetState($hSitem[$i], $GUI_UNCHECKED)
                                Next
                        ElseIf BitAND(GUICtrlRead($hFitem01), $GUI_UNCHECKED) Then
                                GUICtrlSetState($hFitem01, $GUI_CHECKED)
                                For $i = 1 To 25
                                        GUICtrlSetState($hSitem[$i], $GUI_CHECKED)
                                Next
                        EndIf
                Case $Button3 ;PNP
                        For $i = 1 To 25
                                If GUICtrlRead($hSitem[$i]) = 1 Then
                                        DirCreate(@ScriptDir & '\' & $i)
                                        MsgBox(0, "提示", $i)
                                EndIf
                        Next
                Case $Button4 ;退出
                        Exit
        EndSwitch
WEnd

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2011-12-28 07:57:24 | 显示全部楼层
如果有代码出来, 我想一定已经有人帮你分析出原因了.
发表于 2011-12-28 09:13:30 | 显示全部楼层
http://www.autoitx.com/thread-23547-1-1.html
至于树形列表,操作类似,仅供参考
发表于 2011-12-28 11:41:02 | 显示全部楼层
树状与本例不同,希望高手提供
发表于 2011-12-28 14:16:47 | 显示全部楼层
逻辑问题最伤神了
发表于 2011-12-28 17:43:26 | 显示全部楼层
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#Region ### START Koda GUI section ### Form= sljowjkjafojnnn klhdjljlj faffas fmaa ska


Dim $hSitem[30], $Line, $list, $Name, $New, $File, $File1, $TreeView1, $hTreeview, $hSitem1

Global $iStyle = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$Form1 = GUICreate("网卡PNP工具", 501, 371, 192, 114)
$Group2 = GUICtrlCreateGroup("", 0, 318, 500, 7)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;~ $Pic1 = GUICtrlCreatePic(@ScriptDir & "\123.jpg", 0, -10, 500, 69)
$Group1 = GUICtrlCreateGroup("", 0, -8, 500, 70)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$hTreeview = GUICtrlCreateTreeView(16, 88, 473, 215, $iStyle, $WS_EX_CLIENTEDGE)
$hFitem01 = GUICtrlCreateTreeViewItem("网卡驱动程序", $hTreeview)

Local $num = 2
For $i = 1 To 25
;~         $File = FileOpen(@ScriptDir & "\setup.ini")
;~         $File = FileReadLine($File, $num)
;~         If $File = "" Then Exit
;~         $Name = StringReplace($File, 'NIC' & $num - 1 & '=', "", 0)
;~         ;MsgBox(0,"提示",$name)
;~         FileClose($File)
;~         $num = $num + 1
;~         $Name = IniRead(@ScriptDir & "\setup.ini", $Name, "name", "")
        $hSitem[$i] = GUICtrlCreateTreeViewItem(StringFormat("%02s","网卡驱动"&$i),$hFitem01)
Next

$Label1 = GUICtrlCreateLabel("请选择对应网卡驱动", 24, 72, 112, 17)
$Button1 = GUICtrlCreateButton("全选", 58, 333, 89, 33)
$Button2 = GUICtrlCreateButton("反选", 168, 333, 89, 33)
$Button3 = GUICtrlCreateButton("开始PNP", 280, 333, 89, 33)
$Button4 = GUICtrlCreateButton("退出", 392, 333, 89, 33)
GUICtrlSetState($hFitem01, $GUI_EXPAND)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $hFitem01
                        If BitAND(GUICtrlRead($hFitem01), $GUI_CHECKED) Then
                                For $i = 1 To 25
                                        GUICtrlSetState($hSitem[$i], $GUI_CHECKED)
                                Next
                        ElseIf BitAND(GUICtrlRead($hFitem01), $GUI_UNCHECKED) Then
                                For $i = 1 To 25
                                        GUICtrlSetState($hSitem[$i], $GUI_UNCHECKED)
                                Next
                        EndIf
                Case $Button1 ;全选

                        GUICtrlSetState($hFitem01, $GUI_CHECKED)
                        For $i = 1 To 25
                                GUICtrlSetState($hSitem[$i], $GUI_CHECKED)
                        Next

                Case $Button2 ;反选
                        Local $num=0
                        Local $flag=False
                        For $i = 1 To 25
                                Local $check=_GUICtrlTreeView_GetChecked($hTreeview, $hSitem[$i])
                                If $check=False Then $num+=1
                                _GUICtrlTreeView_SetChecked($hTreeview,$hSitem[$i], NOT($check))
                        Next
                        
                        If $num>=25 Then $flag=True
                        _GUICtrlTreeView_SetChecked($hTreeview,$hFitem01, $flag)
                        
                Case $Button3 ;PNP
                        For $i = 1 To 25
                                If GUICtrlRead($hSitem[$i]) = 1 Then
;~                                         DirCreate(@ScriptDir & '\' & $i)
                                        MsgBox(0, "提示", $i)
                                EndIf
                        Next
                Case $Button4 ;退出
                        Exit
        EndSwitch
WEnd

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 2011-12-29 15:46:25 | 显示全部楼层
本帖最后由 netegg 于 2011-12-29 18:14 编辑

回复 4# zxxputian1
奇怪,你这个例子不是树形吗,如果说是链接贴子的,我就不多说了,编程不是这么僵化的
另外,可以参考下udf区三态树形的操作
发表于 2012-1-8 09:04:06 | 显示全部楼层
刚好用到 谢谢水木子和蛋蛋
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-15 14:06 , Processed in 0.084477 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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