ini文件怎么读取到GUICtrlCreateTreeview里
本帖最后由 lin0308 于 2009-12-26 14:00 编辑如题,寻求例子,最好有个例子 http://www.autoitx.com/forum.php?mod=viewthread&tid=10606 #include <GuiListView.au3>
#include <GuiImageList.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
$dir = @ScriptDir&"\config.ini"
$Form1 = GUICreate("列表框操作", 280, 270)
$ListView1 = GUICtrlCreateListView("账号 |密码 |", 10, 10, 260, 150)
$Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
$Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
$Label1 = GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
$Label2 = GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
$Label3 = GUICtrlCreateLabel("数据", 200, 223, 36, 17)
$Label4 = GUICtrlCreateLabel("0", 230, 223, 36, 17)
GUISetState(@SW_SHOW)
Read()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
tian()
EndSwitch
WEnd
Func Read()
$z = 0
_GUICtrlListView_DeleteAllItems($ListView1)
$read = IniReadSection($dir,"config")
If Not @error Then
For $i = 1 To $read
GUICtrlCreateListViewItem($read[$i], $ListView1)
_GUICtrlListView_AddSubItem($ListView1, $z, $read[$i], 1, $z+1)
GUICtrlSetData($Label4,$z+1)
$z += 1
Next
EndIf
EndFunc
Func tian()
$z = GUICtrlRead($Label4)
$a = GUICtrlRead($Input1)
$b = GUICtrlRead($Input2)
If $a <> "" And $b <> "" Then
IniWrite($dir,"config",$a,$b)
GUICtrlCreateListViewItem($a, $ListView1)
_GUICtrlListView_AddSubItem($ListView1, $z, $b, 1, $z+1)
MsgBox(0,"提示"," 账号: "&$a&" 密码: "&$b&" 保存成功 ")
GUICtrlSetData($Input1,"")
GUICtrlSetData($Input2,"")
GUICtrlSetData($Label4,$z+1)
EndIf
EndFunc 本帖最后由 水木子 于 2009-12-25 15:10 编辑
估计LS朋友理解错了,LZ是要读取到Treeview,是这意思吧? 本帖最后由 水木子 于 2009-12-25 15:06 编辑
时间匆忙,随便写了一个,不知道有没有问题,将就这看吧!#include <GuiTreeView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$Path = @ScriptDir&"\config.ini"
GUICreate("Treeview", 300, 300)
$TreeView1 = GUICtrlCreateTreeView(2, 2, 296, 280, -1, $WS_EX_CLIENTEDGE)
GUISetState(@SW_SHOW)
Read()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
EndSwitch
WEnd
Func Read()
$all = IniReadSectionNames($Path)
If Not @error Then
For $i = 1 To $all
$a = GUICtrlCreateTreeViewItem($all[$i], $TreeView1)
$var = IniReadSection($Path, $all[$i])
If Not @error Then
For $z = 1 To $var
GUICtrlCreateTreeViewItem($var[$z]&'='&$var[$z], $a)
Next
EndIf
Next
EndIf
EndFuncini配置文件如下:
1-1=32165485
1-2=65456462
1-3=68767854
2-1=65487987
2-2=32321465
2-3=65798795
3-1=52254688
3-2=58778975
3-3=32645678 本帖最后由 xlcwxl 于 2009-12-26 11:16 编辑
我在网上查的:#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
Local $I, $J, $_Tree_Item, $_INI_File = @ScriptDir & "\1.ini"
$Form1 = GUICreate("Form1", 196, 400, 192, 124)
$TreeView = GUICtrlCreateTreeView(16, 16, 137, 361)
For $I = 1 To 9
$IniSection = IniRead($_INI_File, "Main", $I, "None")
If $IniSection = "None" Then ExitLoop
$_Tree_Item[$I] = GUICtrlCreateTreeViewItem($IniSection, $TreeView)
$IniKey = IniReadSection($_INI_File, $I)
If @error Then ExitLoop
For $J = 1 To $IniKey
GUICtrlCreateTreeViewItem($IniKey[$J], $_Tree_Item[$I])
Next
GUICtrlSetState($_Tree_Item[$I], BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
Next
GUISetState(@SW_SHOW)
While 1
If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit
WEnd
INI文件名:1.ini, 内容:
1=股票经济
2=聊天通讯
1=大智慧
2=民生证券
1=飞信2008
这个比较实用 留个记号! 留个记号,以后再看 怎么又没钱了 呵呵留下脚印 学习了。多谢分享。 学习了。。呵呵 学习了。。呵呵 学习了,感谢,万分感谢
页:
[1]