找回密码
 加入
搜索
查看: 2495|回复: 5

[AU3基础] [已解决] ini配置读取写入问题。谢谢

[复制链接]
发表于 2011-2-18 21:48:35 | 显示全部楼层 |阅读模式
本帖最后由 pingfan5888 于 2011-2-19 01:40 编辑

cfg.ini

[config]
dir=E:\汽车\凯美瑞\
[title]
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[0][0]

                GUICtrlSetData($Combo1,$var[$i][0])
    Next
EndIf
EndFunc
发表于 2011-2-18 23:10:13 | 显示全部楼层
$var=inireadsection("cfg.ini","title")
for $i=1 to $var[0][0]
msgbox(0, "", "Title: " & $var[$i][0] & @CRLF & "Dir: " & $var[$i][1])
next
 楼主| 发表于 2011-2-18 23:17:35 | 显示全部楼层
谢谢2楼的,我刚好也找到了,现在就是测试显示 $txt 没有东西啊,怎么改。
 楼主| 发表于 2011-2-19 01:39:25 | 显示全部楼层
自己解决了。
发表于 2011-2-19 01:50:33 | 显示全部楼层
回复 4# pingfan5888


    解决了请贴出方法,方便新手查阅。
 楼主| 发表于 2011-2-19 02:07:46 | 显示全部楼层
本帖最后由 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[0][0]
                GUICtrlSetData($Combo1,$var[$i][0])
    Next
EndIf
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-10-2 14:22 , Processed in 0.077529 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表