求判断单选,然后在反选,反选后的问题 附源码
本帖最后由 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, $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 如果有代码出来, 我想一定已经有人帮你分析出原因了. http://www.autoitx.com/thread-23547-1-1.html
至于树形列表,操作类似,仅供参考 树状与本例不同,希望高手提供 逻辑问题最伤神了{:face (258):} #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, $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
本帖最后由 netegg 于 2011-12-29 18:14 编辑
回复 4# zxxputian1
奇怪,你这个例子不是树形吗,如果说是链接贴子的,我就不多说了,编程不是这么僵化的
另外,可以参考下udf区三态树形的操作 刚好用到 谢谢水木子和蛋蛋
页:
[1]