找回密码
 加入
搜索
查看: 9701|回复: 25

列表框读取ini文件

 火.. [复制链接]
发表于 2009-10-29 12:05:26 | 显示全部楼层 |阅读模式
本帖最后由 xlcwxl 于 2009-10-29 13:37 编辑

如图:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
Dim $dir = "user.ini"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 264, 221, 192, 114)
$Label1 = GUICtrlCreateLabel("用户名", 8, 168, 40, 17)
$Input1 = GUICtrlCreateInput("", 48, 168, 121, 21)
$Label2 = GUICtrlCreateLabel("密码", 8, 192, 28, 17)
$Input2 = GUICtrlCreateInput("", 48, 192, 121, 21)
$Button1 = GUICtrlCreateButton("添加", 176, 168, 75, 25)
$ListView1 = GUICtrlCreateListView("", 8, 8, 242, 150)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) 
; Add columns
_GUICtrlListView_AddColumn($ListView1, "用户名", 100)
_GUICtrlListView_AddColumn($ListView1, "密码", 82)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
add()
EndSwitch
WEnd

Func add()
$i = 0
While 1
$i += 1
IniReadSection($dir, "账号" & $i)
If @error Then ExitLoop
WEnd
IniWrite($dir, "账号" & $i, "账号", GUICtrlRead($Input1))
IniWrite($dir, "账号" & $i, "密码", GUICtrlRead($Input2))
EndFunc 

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-10-29 12:14:48 | 显示全部楼层
ini的格式上建議修飾為...

[帳號]
01=帳號,密碼
02=帳號,密碼
03=帳號,密碼
依序到底...
发表于 2009-10-29 12:31:46 | 显示全部楼层
1# xlcwxl

配置文件的格式可以这样写,更方便。

[config]
账号=密码
账号=密码
账号=密码
......
......
N
发表于 2009-10-29 12:40:42 | 显示全部楼层
本帖最后由 netegg 于 2009-10-29 12:42 编辑

$array = iniread($file)
$i =1
do
$subarray = inireadsection($file, $array[$i])
Guicreatelistviewitem($subarray[1] & "|" & $subarray[2], $hListview)
$i += 1
until $i= $array[0]
 楼主| 发表于 2009-10-29 12:48:29 | 显示全部楼层
原来ini可以这么写
感谢楼上的回答
发表于 2009-10-29 13:07:45 | 显示全部楼层
本帖最后由 水木子 于 2009-10-29 13:30 编辑

时间仓促,随便写的,试试!
#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, 250)
$ListView1 = GUICtrlCreateListView("账号           |密码           |", 10, 10, 260, 150)
$Button1 = GUICtrlCreateButton("添加", 185, 178, 75, 65, $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)
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[0][0]
                        GUICtrlCreateListViewItem($read[$i][0], $ListView1)
                        _GUICtrlListView_AddSubItem($ListView1, $z, $read[$i][1], 1, $z+1)
                        $z += 1                
                Next
        EndIf
EndFunc

Func tian()
        $a = GUICtrlRead($Input1)
        $b = GUICtrlRead($Input2)
        
        If $a <> "" And $b <> "" Then 
                IniWrite($dir,"config",$a,$b)
                MsgBox(0,"提示"," 账号: "&$a&" 密码: "&$b&" 保存成功 ")
                Read()
                GUICtrlSetData($Input1,"")
                GUICtrlSetData($Input2,"")
        EndIf        
EndFunc        

评分

参与人数 1金钱 +30 贡献 +10 收起 理由
kn007 + 30 + 10 感谢你对论坛的支持,希望以后继续发扬这种 ...

查看全部评分

 楼主| 发表于 2009-10-29 13:20:50 | 显示全部楼层
一闪就没了
发表于 2009-10-29 13:29:12 | 显示全部楼层
本帖最后由 水木子 于 2009-10-29 13:31 编辑

7# xlcwxl

上面6楼代码已经做了修改,再试试呢?

评分

参与人数 1金钱 +10 收起 理由
xlcwxl + 10 已解决,谢谢你的帮助

查看全部评分

发表于 2009-10-29 15:05:18 | 显示全部楼层
不错啊,水木子
发表于 2009-10-29 15:20:37 | 显示全部楼层
正需要这个
发表于 2009-10-29 15:49:52 | 显示全部楼层
本帖最后由 水木子 于 2009-10-29 15:59 编辑
不错啊,水木子
kn007 发表于 2009-10-29 15:05


呵呵! 哪里,哪里!   “只是不断的帮助他人,才能得到他人的帮助”
我还得多向大家学习呢!
发表于 2009-10-29 17:42:24 | 显示全部楼层
抽空整理了一下,感觉这样写更合理。
尤其针对数据多,并再新增数据的时候,不用重新刷新。
#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[0][0]
                        GUICtrlCreateListViewItem($read[$i][0], $ListView1)
                        _GUICtrlListView_AddSubItem($ListView1, $z, $read[$i][1], 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        

评分

参与人数 1金钱 +11 贡献 +10 收起 理由
kn007 + 11 + 10 感谢你对论坛的支持,希望以后继续发扬这种 ...

查看全部评分

发表于 2009-11-1 15:16:12 | 显示全部楼层
学习了,感谢大家
发表于 2009-11-4 08:24:47 | 显示全部楼层
做个记号 以后用到
发表于 2009-12-18 22:52:45 | 显示全部楼层
收藏学习~~~~~~~~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-29 01:18 , Processed in 0.146424 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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