回复 4# kk_lee69
这是config.ini[1]
;功能名称
1.Name=功能1
;类图标
1.ICon=1.ico
;是否默认展开(0/1,否/是)
1.expand=1
1.1.ex1=选中与否
1.1.ex2=名称
1.1.ex3=路径
1.1.ex4=参数
1.1.ex5=时间
1.1.ex6=隐藏
1.2.ex1=1
1.2.ex2=3
1.2.ex3=4
1.2.ex4=5
1.2.ex5=6
[2]
2.Name=功能2
2.Icon=2.ico
2.Expand=1
2.1.ex1=开关
2.1.ex2=名称
2.1.ex3=路径
2.1.ex4=参数
2.1.ex5=时间
2.1.ex6=隐藏
2.2.ex1=1
2.2.ex2=3
2.2.ex3=4
2.2.ex4=5
2.2.ex5=6
[3]
3.Name=功能3
3.Icon=3.ico
3.Expand=1
3.1.ex1=开关
3.1.ex2=名称
3.1.ex3=运行时间
3.1.ex4=灵敏度
3.1.ex5=映像名
3.1.ex6=路径
3.2.ex1=1
3.2.ex2=3
3.2.ex3=4
3.2.ex4=5
3.2.ex5=6
[4]
4.Name=功能4
4.Icon=4.ico
4.Expand=1
4.1.ex1=开关
4.1.ex2=名称
4.1.ex3=路径
4.1.ex4=参数
4.1.ex5=图标
4.1.ex6=图标编号
4.2.ex1=1
4.2.ex2=3
4.2.ex3=4
4.2.ex4=5
4.2.ex5=6
[5]
5.Name=功能5
5.Icon=5.ico
5.Expand=1
5.1.ex1=开关
5.1.ex2=路径
5.1.ex3=1
5.1.ex4=1
5.1.ex5=1
5.2.ex1=1
5.2.ex2=路径
5.2.ex3=1
5.2.ex4=1
5.2.ex5=1
#include <GuiTreeView.au3>
;~ #include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <Array.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
Global Const $inifile = @ScriptDir & "\config.ini"
Global $gu_form1 = GUICreate("", 592, 420, -1, -1)
Global $gu_Treeview1 = GUICtrlCreateTreeView(16, 16, 177, 342, BitOR($gui_ss_default_treeview, $tvs_checkboxes, $ws_border))
$gu_button1 = GUICtrlCreateButton("", 450, 370, 50, 30, $BS_FLAT)
$gu_button2 = GUICtrlCreateButton("", 510, 370, 50, 30, $BS_FLAT)
Global $up_form[6], $up_input[6][5], $up_button[6][5], $up_group[6] = ["", "功能1", "功能2", "功能3", "功能4", "功能5"]
Local $z
For $z = 1 To 5
$up_form[$z] = GUICreate("", 367, 345, 209, 13, $WS_POPUp, $WS_EX_MDICHILD, $gu_form1)
GUICtrlCreateGroup($up_group[$z], 1, 1, 367, 345)
$up_input[$z][1] = GUICtrlCreateInput("", 26, 50, 250, 20)
$up_input[$z][2] = GUICtrlCreateInput("", 26, 85, 250, 20)
$up_input[$z][3] = GUICtrlCreateInput("", 26, 120, 250, 20)
$up_input[$z][4] = GUICtrlCreateInput("", 26, 150, 250, 20)
$up_button[$z][1] = GUICtrlCreateButton("...", 281, 50, 30, 20, $BS_FLAT)
$up_button[$z][2] = GUICtrlCreateButton("...", 281, 85, 30, 20, $BS_FLAT)
$up_button[$z][3] = GUICtrlCreateButton("...", 281, 120, 30, 20, $BS_FLAT)
$up_button[$z][4] = GUICtrlCreateButton("...", 281, 150, 30, 20, $BS_FLAT)
Next
GUISetState(@SW_SHOW, $gu_form1)
Global $Array = _IniToArray($inifile)
_main()
Exit
Func _main()
_createtree($Array)
Local $aArray=$Array
While 1
Local $nMsg = GUIGetMsg()
_TreeViewCTL($Array, $nMsg)
_buttonCTL($aArray,$nMsg)
WEnd
EndFunc ;==>_main
Func _IniToArray($inifile)
Local $Array[1][8], $p = 1
Local $i = 1
While 1
Local $clsName = IniRead($inifile, $i, $i & ".Name", "")
If $clsName = "" Then ExitLoop
ReDim $Array[$p + 1][8]
$Array[$p][1] = "root"
$Array[$p][2] = 0
$Array[$p][3] = IniRead($inifile, $i, $i & ".Name", "")
$Array[$p][4] = IniRead($inifile, $i, $i & ".Icon", "")
$Array[$p][5] = IniRead($inifile, $i, $i & ".expand", "")
$p += 1
;~ 开始读取子节点
Local $j = 1
While 1
Local $sw_path = IniRead($inifile, $i, $i & "." & $j & ".ex1", "")
If $sw_path = "" Then ExitLoop
ReDim $Array[$p + 1][8]
$Array[$p][1] = "sub"
$Array[$p][2] = IniRead($inifile, $i, $i & "." & $j & ".ex1", "")
$Array[$p][3] = IniRead($inifile, $i, $i & "." & $j & ".ex2", "")
$Array[$p][4] = IniRead($inifile, $i, $i & "." & $j & ".ex3", "")
$Array[$p][5] = IniRead($inifile, $i, $i & "." & $j & ".ex4", "")
$Array[$p][6] = IniRead($inifile, $i, $i & "." & $j & ".ex5", "")
$Array[$p][7] = IniRead($inifile, $i, $i & "." & $j & ".ex6", "")
$j += 1
$p += 1
WEnd
$i += 1
WEnd
$Array[0][0] = UBound($Array, 1) - 1
Return $Array
EndFunc ;==>_IniToArray
Func _createtree(ByRef $Array)
_GUICtrlTreeView_BeginUpdate($gu_Treeview1)
Local $i
For $i = 1 To $Array[0][0]
Local $root
If $Array[$i][1] = "root" Then
$Array[$i][0] = GUICtrlCreateTreeViewItem($Array[$i][3], $gu_Treeview1)
$root = $Array[$i][0]
Else
$Array[$i][0] = GUICtrlCreateTreeViewItem($Array[$i][3], $root)
EndIf
Next
Local $i
For $i = $Array[0][0] To 1 Step -1
If $Array[$i][2] = 1 Then
_GUICtrlTreeView_SetChecked($gu_Treeview1, $Array[$i][0], True)
EndIf
If $Array[$i][1] = "root" And $Array[$i][5] = 1 Then
_GUICtrlTreeView_Expand($gu_Treeview1, $Array[$i][0], True)
EndIf
Next
_GUICtrlTreeView_EndUpdate($gu_Treeview1)
EndFunc ;==>_createtree
Func _TreeViewCTL(ByRef $Array, $nMsg)
Local $i
For $i = 1 To $Array[0][0]
Switch $nMsg
Case $Array[$i][0]
_DisplaysGui($i, $Array)
;主节点
If $Array[$i][1] = "root" Then
If _GUICtrlTreeView_GetChecked($gu_Treeview1, $Array[$i][0]) = True _
And $Array[$i][2] = 0 Then
$Array[$i][2] = 1
Local $j
For $j = $i + 1 To $Array[0][0]
If $Array[$j][1] = "sub" Then
_GUICtrlTreeView_SetChecked($gu_Treeview1, $Array[$j][0], True)
$Array[$j][2] = 1
Else
ExitLoop
EndIf
Next
ElseIf _GUICtrlTreeView_GetChecked($gu_Treeview1, $Array[$i][0]) = False _
And $Array[$i][2] = 1 Then
$Array[$i][2] = 0
Local $j
For $j = $i + 1 To $Array[0][0]
If $Array[$j][1] = "sub" Then
_GUICtrlTreeView_SetChecked($gu_Treeview1, $Array[$j][0], False)
$Array[$j][2] = 0
Else
ExitLoop
EndIf
Next
EndIf
;节点,节点若被选中,主节点则被选中
ElseIf $Array[$i][1] = "sub" Then
If _GUICtrlTreeView_GetChecked($gu_Treeview1, $Array[$i][0]) = True _
And $Array[$i][2] = 0 Then
$Array[$i][2] = 1
Local $j
For $j = $i - 1 To 1 Step -1
If $Array[$j][1] = "root" Then
_GUICtrlTreeView_SetChecked($gu_Treeview1, $Array[$j][0], True)
$Array[$j][2] = 1
ExitLoop
EndIf
Next
ElseIf _GUICtrlTreeView_GetChecked($gu_Treeview1, $Array[$i][0]) = False _
And $Array[$i][2] = 1 Then
$Array[$i][2] = 0
Local $roothdl
Local $flag = 0
Local $j
;向前,查找其他节点状态
For $j = $i + 1 To $Array[0][0]
If $Array[$j][1] = "root" Then
ExitLoop
Else
If _GUICtrlTreeView_GetChecked($gu_Treeview1, $Array[$j][0]) = True Then
$flag = 1
ExitLoop
EndIf
EndIf
Next
;向后查找其他节点状态
For $j = $i - 1 To 1 Step -1
If $Array[$j][1] = "root" Then
$roothdl = $Array[$j][0]
ExitLoop
Else
If _GUICtrlTreeView_GetChecked($gu_Treeview1, $Array[$j][0]) = True Then
$flag = 1
ExitLoop
EndIf
EndIf
Next
If $flag = 0 Then
_GUICtrlTreeView_SetChecked($gu_Treeview1, $roothdl, False)
$Array[$j][2] = 0
EndIf
EndIf
EndIf
EndSwitch
Next
;显示视图的具体内容
EndFunc ;==>_TreeViewCTL
Func _DisplaysGui($i, $Array)
;$j 归属
;$i 位置
GUISetState(@SW_HIDE, $up_form[1])
GUISetState(@SW_HIDE, $up_form[2])
GUISetState(@SW_HIDE, $up_form[3])
GUISetState(@SW_HIDE, $up_form[4])
GUISetState(@SW_HIDE, $up_form[5])
Local $j
If $Array[$i][1] = "root" Then
$j = $i
Else
For $j = $i To 1 Step -1
If $Array[$j][1] = "root" Then ExitLoop
Next
EndIf
Switch $Array[$j][3]
Case "功能1"
GUISetState(@SW_SHOW, $up_form[1])
GUICtrlSetData($up_button[1][1], "路径")
GUICtrlSetData($up_button[1][2], "参数")
GUICtrlSetData($up_button[1][3], "隐藏")
GUICtrlSetData($up_button[1][4], "延迟")
If $j = $i Then
GUICtrlSetData($gu_button2, "添加(&t)")
GUICtrlSetState($gu_button1, $GUI_DISABLE)
Else
GUICtrlSetState($gu_button1, $GUI_ENABLE)
GUICtrlSetData($gu_button2, "应用(&a)")
GUICtrlSetData($gu_button1, "删除(&t)")
GUICtrlSetData($up_input[1][1], $Array[$i][4])
GUICtrlSetData($up_input[1][2], $Array[$i][5])
GUICtrlSetData($up_input[1][3], $Array[$i][6])
GUICtrlSetData($up_input[1][4], $Array[$i][7])
EndIf
Case "功能2"
GUISetState(@SW_SHOW, $up_form[2])
GUICtrlSetData($up_button[2][1], "路径")
GUICtrlSetData($up_button[2][2], "参数")
GUICtrlSetData($up_button[2][3], "隐藏")
GUICtrlSetData($up_button[2][4], "延迟")
If $j = $i Then
GUICtrlSetData($gu_button2, "添加(&t)")
GUICtrlSetState($gu_button1, $GUI_DISABLE)
Else
GUICtrlSetState($gu_button1, $GUI_ENABLE)
GUICtrlSetData($gu_button2, "应用(&a)")
GUICtrlSetData($gu_button1, "删除(&t)")
GUICtrlSetData($up_input[2][1], $Array[$i][4])
GUICtrlSetData($up_input[2][2], $Array[$i][5])
GUICtrlSetData($up_input[2][3], $Array[$i][6])
GUICtrlSetData($up_input[2][4], $Array[$i][7])
EndIf
Case "功能3"
GUISetState(@SW_SHOW, $up_form[3])
GUICtrlSetData($up_button[3][1], "路径")
GUICtrlSetData($up_button[3][2], "参数")
GUICtrlSetData($up_button[3][3], "隐藏")
GUICtrlSetData($up_button[3][4], "延迟")
If $j = $i Then
GUICtrlSetData($gu_button2, "添加(&t)")
GUICtrlSetState($gu_button1, $GUI_DISABLE)
Else
GUICtrlSetState($gu_button1, $GUI_ENABLE)
GUICtrlSetData($gu_button2, "应用(&a)")
GUICtrlSetData($gu_button1, "删除(&t)")
GUICtrlSetData($up_input[3][1], $Array[$i][4])
GUICtrlSetData($up_input[3][2], $Array[$i][5])
GUICtrlSetData($up_input[3][3], $Array[$i][6])
GUICtrlSetData($up_input[3][4], $Array[$i][7])
EndIf
Case "功能4"
GUISetState(@SW_SHOW, $up_form[4])
GUICtrlSetData($up_button[4][1], "路径")
GUICtrlSetData($up_button[4][2], "参数")
GUICtrlSetData($up_button[4][3], "隐藏")
GUICtrlSetData($up_button[4][4], "延迟")
If $j = $i Then
GUICtrlSetData($gu_button2, "添加(&t)")
GUICtrlSetState($gu_button1, $GUI_DISABLE)
Else
GUICtrlSetState($gu_button1, $GUI_ENABLE)
GUICtrlSetData($gu_button2, "应用(&a)")
GUICtrlSetData($gu_button1, "删除(&t)")
GUICtrlSetData($up_input[4][1], $Array[$i][4])
GUICtrlSetData($up_input[4][2], $Array[$i][5])
GUICtrlSetData($up_input[4][3], $Array[$i][6])
GUICtrlSetData($up_input[4][4], $Array[$i][7])
EndIf
Case "功能5"
GUISetState(@SW_SHOW, $up_form[5])
GUICtrlSetData($up_button[5][1], "路径")
GUICtrlSetData($up_button[5][2], "参数")
GUICtrlSetData($up_button[5][3], "隐藏")
GUICtrlSetData($up_button[5][4], "延迟")
If $j = $i Then
GUICtrlSetData($gu_button2, "添加(&t)")
GUICtrlSetState($gu_button1, $GUI_DISABLE)
Else
GUICtrlSetState($gu_button1, $GUI_ENABLE)
GUICtrlSetData($gu_button2, "应用(&a)")
GUICtrlSetData($gu_button1, "删除(&t)")
GUICtrlSetData($up_input[5][1], $Array[$i][4])
GUICtrlSetData($up_input[5][2], $Array[$i][5])
GUICtrlSetData($up_input[5][3], $Array[$i][6])
GUICtrlSetData($up_input[5][4], $Array[$i][7])
EndIf
EndSwitch
EndFunc ;==>_DisplaysGui
Func _buttonCTL(ByRef $aArray,$nMsg)
Local $i, $j
For $j = 1 To UBound($Array)-1 ;8194
If _GUICtrlTreeView_GetSelected($gu_Treeview1, $Array[$j][0]) Then ExitLoop
Next
For $i = 1 To 5
Switch $nMsg
Case $up_button[$i][1]
Case $up_button[$i][2]
Case $up_button[$i][3]
Case $up_button[$i][4]
EndSwitch
Next
Switch $nMsg
Case $gu_button1
_GUICtrlTreeView_BeginUpdate($gu_Treeview1)
_GUICtrlTreeView_Delete($gu_Treeview1,$Array[$j][0])
_GUICtrlTreeView_EndUpdate($gu_Treeview1)
Case $gu_button2
Case $gui_event_close
Exit
EndSwitch
EndFunc ;==>_buttonCTL
我现在的做法是添加项目直接写入到ini里,但需要重新启动才能生效,
修改的话简单点,可以直接修改数组中的元素,然后删除ini,把数组写入到新的ini中
删除的话,是在数组中添加一个删除的标记,然后删除ini,把数组写入到新的ini中
删除和修改功能算是基本实现了,但添加功能就差点意思
我想问问有什么好的解决办法吗? |