[已解决] ini配置读取写入问题。谢谢
本帖最后由 pingfan5888 于 2011-2-19 01:40 编辑cfg.ini
dir=E:\汽车\凯美瑞\
2010=F:\图片下载\2010\
wallpaper=E:\我的文档\Wallpaper\Wallpaper\
....
文件夹1=E:\我的文档\Wallpaper\Wallpaper\
....
我想把title 中的参数读取赋到编辑下拉框中:2010,wallpaper,,,,,文件夹1 ,显示出标题。
然后在把编辑框中选择的文件夹的路径写入到dir=
中,可哪位大大帮助下,谢谢。
现在测试显示$txt 没有东西啊。所以取不了值写入。
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=F:\au3\img.kxf
$Form1 = GUICreate("Form1", 633, 450, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 16, 24, 249, 25)
$Button1 = GUICtrlCreateButton("运行", 280, 24, 89, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
read()
$txt = GUICtrlRead($Combo1)
$dir = IniRead(@ScriptDir & "\cfg.ini", "title", $txt,"")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
IniWrite(@ScriptDir & "\cfg.ini", "config", "dir", $dir)
;MsgBox(4096, "", $txt)
EndSwitch
WEnd
Func read()
$var = IniReadSection(@ScriptDir & "\cfg.ini", "title")
If @error Then
MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
For $i = 1 To $var
GUICtrlSetData($Combo1,$var[$i])
Next
EndIf
EndFunc $var=inireadsection("cfg.ini","title")
for $i=1 to $var
msgbox(0, "", "Title: " & $var[$i] & @CRLF & "Dir: " & $var[$i])
next 谢谢2楼的,我刚好也找到了,现在就是测试显示 $txt 没有东西啊,怎么改。 自己解决了。 回复 4# pingfan5888
解决了请贴出方法,方便新手查阅。 本帖最后由 pingfan5888 于 2011-2-19 02:09 编辑
解决好的代码:
#NoTrayIcon
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=F:\au3\img.kxf
$Form1 = GUICreate("图片保存", 410, 62, 192, 124)
$Combo1 = GUICtrlCreateCombo("", 8, 20, 201, 25,$CBS_DROPDOWNLIST)
$Button1 = GUICtrlCreateButton("运行", 216, 20, 89, 25)
$Button2 = GUICtrlCreateButton("取消", 312, 20, 89, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
If Not FileExists(@ScriptDir & "\cfg.ini") Then
GUISetState(@SW_HIDE)
msgbox(16,'警告','请把本程序放于软件根目录')
Exit
EndIf
read()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
IniWrite(@ScriptDir & "\cfg.ini", "config", "dir", IniRead(@ScriptDir & "\cfg.ini", "folder", GUICtrlRead($Combo1),""))
Run(@ScriptDir & "\saver.exe")
Exit
Case $Button2
Exit
EndSwitch
WEnd
Func read()
$var = IniReadSection(@ScriptDir & "\cfg.ini", "folder")
If @error Then
MsgBox(4096, "", "Error occurred, probably no INI file.")
Else
For $i = 1 To $var
GUICtrlSetData($Combo1,$var[$i])
Next
EndIf
EndFunc
页:
[1]