本帖最后由 水木子 于 2010-10-28 10:13 编辑
#include <GUIListBox.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
Local $sConfigPath = @ScriptDir & '\Config.ini'
Local $f = -1, $s = -1
$aRegFitem = StringRegExp(FileRead($sConfigPath), '\[.+\]', 3)
$aRegSitem = StringRegExp(FileRead($sConfigPath), '=', 3)
Local $aFitem[UBound($aRegFitem)][2], $aSitem[UBound($aRegSitem)][2]
Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES)
$Form1 = GUICreate('TreeView', 600, 450)
$TreeView1 = GUICtrlCreateTreeView(5, 5, 200, 440, $iStyle, $WS_EX_CLIENTEDGE)
$List1 = GUICtrlCreateList('', 210, 5, 385, 300)
GUICtrlCreateGroup('', 210, 300, 385, 140)
$Label1 = GUICtrlCreateLabel('准备安装:', 230, 320, 360, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel('0.0%', 540, 350, 50, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Progress1 = GUICtrlCreateProgress(230, 350, 300, 20)
GUICtrlCreateLabel("安装路径:", 230, 398, 100, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 310, 398, 200, 21)
$But1 = GUICtrlCreateButton("开始", 520, 396, 60, 25, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
ConfigRead()
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $aFitem[0][0] To $aSitem[UBound($aSitem) - 1][0] ;父项目 $aFitem[UBound($aFitem) - 1][0]
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_CHECKED)
Next
Else
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $nMsg))
For $i = $nMsg To $nMsg + $iSitemNumber
GUICtrlSetState($i, $GUI_UNCHECKED)
Next
EndIf
;Case $aSitem[0][0] To $aSitem[UBound($aSitem) - 1][0] ;子项目
If BitAND(GUICtrlRead($nMsg), $GUI_CHECKED) Then
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
GUICtrlSetState($hFitemHandle, $GUI_CHECKED)
Else
$hFitemHandle = _GUICtrlTreeView_GetParentParam($TreeView1, $nMsg)
$iSitemNumber = Number(_GUICtrlTreeView_GetChildCount($TreeView1, $hFitemHandle))
For $i = $hFitemHandle To $hFitemHandle + $iSitemNumber
If GUICtrlRead($i) = $GUI_CHECKED Then ExitLoop
If $i = $hFitemHandle + $iSitemNumber Then GUICtrlSetState($hFitemHandle, $GUI_UNCHECKED)
Next
EndIf
$x = 1
$sItemText = ''
GUICtrlSetData($List1, '') ;清空List内所有数据
For $i = 0 To UBound($aSitem) - 1
If _GUICtrlTreeView_GetChecked($TreeView1, $aSitem[$i][0]) Then
GUICtrlSetData($List1, StringFormat("[%02d]", $x) & $aSitem[$i][1]) ;如果项目被勾选则写入List
$sItemText &= $aSitem[$i][1] & '|'
$x += 1
EndIf
Next
Case $But1
BeginInstall()
EndSwitch
WEnd
Func ConfigRead()
$var1 = IniReadSectionNames($sConfigPath)
If Not @error Then
For $i = 1 To $var1[0]
$f += 1
$aFitem[$f][0] = GUICtrlCreateTreeViewItem($var1[$i], $TreeView1)
$aFitem[$f][1] = $var1[$i]
$var2 = IniReadSection($sConfigPath, $var1[$i])
For $n = 1 To $var2[0][0]
$s += 1
$aSitem[$s][0] = GUICtrlCreateTreeViewItem($var2[$n][0], $aFitem[$f][0])
$aSitem[$s][1] = $var2[$n][0]
Next
Next
EndIf
EndFunc ;==>ConfigRead
Func BeginInstall()
$aLines = StringSplit($sItemText, '|', 2)
$iNumber1 = 100 / (UBound($aLines) - 1)
$iNumber2 = $iNumber1
For $i = 0 To UBound($aLines) - 2
GUICtrlSetData($Label1, '正在安装:' & $aLines[$i])
_GUICtrlListBox_ReplaceString($List1, $i, '[→]' & $aLines[$i])
_GUICtrlListBox_SetCurSel($List1, $i)
Sleep(800)
_GUICtrlListBox_ReplaceString($List1, $i, '[OK]' & $aLines[$i])
_GUICtrlListBox_SetCurSel($List1, $i)
GUICtrlSetData($Progress1, $iNumber1)
GUICtrlSetData($Label2, StringFormat('%.1f%', $iNumber1))
$iNumber1 += $iNumber2
Next
GUICtrlSetData($Label1, '安装完成')
EndFunc ;==>BeginInstall
Config.ini 如下
|