找回密码
 加入
搜索
查看: 3904|回复: 11

列表框 读+写+删+修改

[复制链接]
发表于 2009-7-20 21:16:02 | 显示全部楼层 |阅读模式
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>  ;清空ListView1需要的文件


Global $Config_File = @ScriptDir & "\config.ini"


#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form1 = GUICreate("配置工具", 633, 447, 601, 241)
$ListView1 = GUICtrlCreateListView("排列|要监控的进程", 80, 24, 466, 318)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 300)
$Button1 = GUICtrlCreateButton("添加", 289, 368, 75, 25, 0)
$Button2 = GUICtrlCreateButton("修改", 384, 369, 75, 25, 0)
$Button3 = GUICtrlCreateButton("删除", 480, 369, 75, 25, 0)
$Input1 = GUICtrlCreateInput("", 80, 368, 177, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


add_list()



While 1
$nMsg = GUIGetMsg()
Switch $nMsg
        Case $GUI_EVENT_CLOSE
                Exit
        
        Case $Button1
                Button1()
                
        Case $Button2
                Button2()
                
        Case $Button3
                Button3()
                
        Case $ListView1
                OKButton()
                
EndSwitch
WEnd

Func OKButton()
  ;注意:此时 @GUI_CTRLID 的值将等价于 $okbutton
  MsgBox(0, "GUI 事件", "您按下了“还OK吧”按钮!")
EndFunc

Func add_list();读取 ListView1

        $var_S = IniReadSection($Config_File, "进程")  ;读取美工接种的所有关键字或值

        For $n = 1 To $var_S[0][0]                                                ;循环
                
                GUICtrlCreateListViewItem($var_S[$n][0] & "|" & $var_S[$n][1] , $ListView1)        ;在GUI上创建一个ListView项目控件
                
        Next
                
EndFunc   ;==>add_list()


Func Button1();添加一个ListView1

        $var_S = IniReadSection($Config_File, "进程")  ;读取美工接种的所有关键字或值

        For $n = 1 To $var_S[0][0]                                                ;循环
                
        Next

                $data1 = GUICtrlRead($Input1)        ;读取指定控件的状态或相关数据
        ConsoleWrite($data1)                        ;写入数据
                IniWrite ( $Config_File, "进程", $n+1, $data1 )        ;写入INI.
                
                _GUICtrlListView_DeleteAllItems($ListView1);清空 ListView1
                
                add_list() ;读取 ListView1

EndFunc   ;==>Button1()
        
        
Func Button2()
        

                
EndFunc   ;==>Button2()
        
        
Func Button3()
        

                
EndFunc   ;==>Button2()
        
config.ini  配置文件
[进程]
1=1.exe
3=2.exe
4=3.exe
5=4.exe
6=1
各位帮帮忙。本人写了一下的源码,现在只会做到读和写,
可是修改和删除就不会弄,。
请各位帮帮忙
发表于 2009-7-20 21:23:01 | 显示全部楼层
Func Button3()      
_GUICtrlListView_DeleteItemsSelected($ListView1)               
EndFunc   ;==>Button2()
上面只删除列表显示的
还要inidelete相关项
自己写写吧
发表于 2009-7-20 21:29:08 | 显示全部楼层
至于修改
看下帮助文件的_GUICtrlListView_EditLabel例子
发表于 2009-7-20 22:25:31 | 显示全部楼层
本帖最后由 水木子 于 2009-7-20 22:34 编辑

看看吧!我刻意加了注释,应该容易读。
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $dir = "QQ.ini"
$Form1 = GUICreate("Form1", 301, 301, 192, 124)
$List1 = GUICtrlCreateList("", 65, 50, 180, 97)
$Input1 = GUICtrlCreateInput("", 108, 160, 120, 21, BitOR($ES_AUTOHSCROLL, $WS_BORDER))
$Input2 = GUICtrlCreateInput("", 108, 200, 120, 21, BitOR($ES_LOWERCASE, $ES_PASSWORD, $WS_BORDER))
$Label1 = GUICtrlCreateLabel("账号:", 50, 160, 52, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Label2 = GUICtrlCreateLabel("密码:", 50, 200, 52, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("添加", 20, 250, 75, 25, $WS_GROUP)
$Button2 = GUICtrlCreateButton("删除", 115, 250, 75, 25, $WS_GROUP)
$Button3 = GUICtrlCreateButton("退出", 210, 250, 75, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
refresh()
 
;~ GUICtrlSetData($List1, $xs)                      ;修改指定控件上的文本
 
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1   ;保存
                        save()
                Case $Button2   ;删除
                        del()
                Case $Button3   ;退出
                        Exit
        EndSwitch
WEnd
 
Func refresh()
        GUICtrlSetData($List1,"")          ;修改指定控件的数据
        $var = IniReadSectionNames($dir)   ;从某标准配置文件(*.ini)中读取所有字段的信息.
        If @error Then
                MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
        Else
                For $i = 1 To $var[0]
                        GUICtrlSetData($List1, IniRead($dir, $var[$i], "zh", "Not Found"))
                                                ;修改指定控件的数据.从某标准配置文件(*.ini)中读取某个数值.

                Next
        EndIf
EndFunc   ;==>refresh
 
Func save()
        $i = 0
        While 1
                $i += 1
                IniReadSection($dir, "QQ" & $i)   ;从某标准配置文件(*.ini)中读取某个节中的所有关键字或值.

                If @error Then ExitLoop
        WEnd
        IniWrite($dir, "QQ" & $i, "zh", GUICtrlRead($Input1)) ;将读取到的值写入ini文件
        IniWrite($dir, "QQ" & $i, "mm", GUICtrlRead($Input2)) ;将读取到的值写入ini文件
        ;MsgBox(0,0,"保存成功")
        refresh()
EndFunc   ;==>save
 
Func del()
        $var = IniReadSectionNames($dir)
        If @error Then
                MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
        Else
                For $i = 1 To $var[0]
                        If IniRead($dir, $var[$i], "zh", "Not Found") = GUICtrlRead($List1) Then
                                IniDelete($dir, $var[$i])
                                ;MsgBox(0, 0, "删除成功")
                                refresh()
                        EndIf
                Next
        EndIf
EndFunc   ;==>del

评分

参与人数 1金钱 +20 贡献 +10 收起 理由
kn007 + 20 + 10 原创内容,感谢你对论坛的支持;希望继续发 ...

查看全部评分

发表于 2009-7-21 18:31:27 | 显示全部楼层
学习一下。。
 楼主| 发表于 2009-7-22 04:02:24 | 显示全部楼层
本帖最后由 116154801 于 2009-7-22 04:06 编辑

列表框 List.au3
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $dir = "config.ini"
del1()  ;删除 = 号
IniWrite ( $dir, "进程", "病毒.exe", "" )        ;写入INI.


#Region ### START Koda GUI section ### Form=E:\D\1.苹果工程技术学院\0.编辑文件备份\l.列表框\工程1.kxf
$Form1 = GUICreate("配置工具", 633, 447, 601, 241)
$Button1 = GUICtrlCreateButton("添加", 289, 368, 75, 25, 0)
$Button2 = GUICtrlCreateButton("修改", 384, 369, 75, 25, 0)
$Button3 = GUICtrlCreateButton("删除", 480, 369, 75, 25, 0)
$Input1 = GUICtrlCreateInput("", 80, 368, 177, 21)
$List1 = GUICtrlCreateList("", 48, 48, 513, 289)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


                del1()  ;删除 留空的 = 号
        refresh() ;获得列表


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1   ;保存
                        save()
                Case $Button2   ;修改
                        xiougai()
                Case $Button3   ;退出
                        del()
                Case $Button2   ;退出
                        GUICtrlSetData($List1,"您点击了第一个按钮!")
        EndSwitch
WEnd

Func refresh()
        GUICtrlSetData($List1,"")          ;修改指定控件的数据
        $var = IniReadSection($dir, "进程")   ;从某标准配置文件(*.ini)中读取所有字段的信息.
        If @error Then
                MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
        Else
                For $i = 1 To $var[0][0]
                        GUICtrlSetData($List1, $var[$i][0])
                                                ;修改指定控件的数据.从某标准配置文件(*.ini)中读取某个数值.

                Next
        EndIf
                del1()  ;删除 留空的 = 号

EndFunc   ;==>refresh

Func save()   ;保存
        $var = IniReadSection($dir, "进程")  ;从某标准配置文件(*..ini)的所有关键字或值

                For $i = 0 To $var[0][0]                                                ;循环
                
                Next
        
        IniWrite($dir, "进程" , GUICtrlRead($Input1) , "") ;将读取到的值写入ini文件
        ;MsgBox(0,0,"保存成功")
                del1()  ;删除 留空的 = 号
        refresh() ;获得列表

EndFunc   ;==>save

Func xiougai()   ;修改


                        GUICtrlSetData($Input1, "111")
EndFunc   ;==>save
        
Func del()  ;删除
                $var = IniReadSection($dir, "进程")   ;从某标准配置文件(*.ini)中读取所有字段的信息.
        If @error Then
                MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
        Else
                For $i = 1 To $var[0][0]
                        If $var[$i][0] = GUICtrlRead($List1) Then         ;If 从没标准配置文件(*.ini)中读取某个数值. =等于  读取制定控件的状态或相关数据  Then
                                IniDelete($dir, "进程" ,$var[$i][0])        ;从某标准配置文件(*..ini)中删除某个数值
                                MsgBox(0, 0, $var[$i][0])
                                refresh()
                        EndIf
                Next
        EndIf
EndFunc   ;==>del
        
        
Func del1()  ;删除 留空的 = 号
                $var = IniReadSection($dir, "进程")   ;从某标准配置文件(*.ini)中读取所有字段的信息.
        If @error Then
                MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
        Else
                For $i = 1 To $var[0][0]
                        If $var[$i][0] = "" Then         ;If 从没标准配置文件(*.ini)中读取某个数值. =等于  读取制定控件的状态或相关数据  Then
                                IniDelete($dir, "进程" ,$var[$i][0])        ;从某标准配置文件(*..ini)中删除某个数值
                                refresh()
                        EndIf
                Next
        EndIf
EndFunc   ;==>del1
 
 


列表框 ListView.au3


#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>  ;清空ListView1需要的文件


Global $dir = @ScriptDir & "\config.ini"

IniWrite ( $dir, "进程2", "1", "病毒.exe" )        ;写入INI.

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\Form1.kxf
$Form1 = GUICreate("配置工具", 633, 447, 601, 241)
$ListView1 = GUICtrlCreateListView("排列|要监控的进程", 80, 24, 466, 318)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 50)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 300)
$Button1 = GUICtrlCreateButton("添加", 289, 368, 75, 25, 0)
$Button2 = GUICtrlCreateButton("修改", 384, 369, 75, 25, 0)
$Button3 = GUICtrlCreateButton("删除", 480, 369, 75, 25, 0)
$Input1 = GUICtrlCreateInput("", 80, 368, 177, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


add_list()




While 1
$nMsg = GUIGetMsg()
Switch $nMsg
        Case $GUI_EVENT_CLOSE
                Exit
        
        Case $Button1
                Button1()
                
        Case $Button2
                Button2()
                
        Case $Button3
                Button3()
                
        Case $ListView1
                OKButton()
                
EndSwitch
WEnd

Func OKButton()
  ;注意:此时 @GUI_CTRLID 的值将等价于 $okbutton
  MsgBox(0, "GUI 事件", "您按下了“还OK吧”按钮!")
EndFunc

Func add_list();读取 ListView1

        $var_S = IniReadSection($dir, "进程2")  ;从某标准配置文件(*..ini)的所有关键字或值

        For $n = 1 To $var_S[0][0]                                                ;循环
                
                GUICtrlCreateListViewItem($var_S[$n][0] & "|" & $var_S[$n][1] , $ListView1)        ;在GUI上创建一个ListView项目控件
                
        Next
                
EndFunc   ;==>add_list()


Func Button1();添加一个ListView1

        $var_S = IniReadSection($dir, "进程2")  ;从某标准配置文件(*..ini)的所有关键字或值

        For $n = 0 To $var_S[0][0]                                                ;循环
                
        Next

                $data1 = GUICtrlRead($Input1)        ;读取指定控件的状态或相关数据
        ConsoleWrite($data1)                        ;写入数据
                IniWrite ( $dir, "进程2", $n+1, $data1 )        ;写入INI.
                
                _GUICtrlListView_DeleteAllItems($ListView1);清空 ListView1
                
                add_list() ;读取 ListView1

EndFunc   ;==>Button1()
        
        
Func Button2()
        
        $var_S = IniReadSection($dir, "进程2")  ;从某标准配置文件(*.ini)的所有关键字或值

        For $n = 0 To $var_S[0][0]                                                ;循环
                
        Next
                _GUICtrlListView_EditLabel("1",$ListView1)
                $data1 = GUICtrlRead($Input1)        ;读取指定控件的状态或相关数据
        ConsoleWrite($data1)                        ;写入数据
                
                IniWrite ( $dir, "进程2", $n+1, $data1 )        ;写入INI.
                
                _GUICtrlListView_DeleteAllItems($ListView1);清空 ListView1
                
                add_list() ;读取 ListView1
        
                
EndFunc   ;==>Button2()
        
        

Func Button3()

        
                $qq = _GUICtrlListView_DeleteItemsSelected($ListView1)
                
                $aItem = _GUICtrlListView_GetItemTextArray($ListView1, 1)

                IniDelete($dir, "进程2" , $aItem)        ;从某标准配置文件(*..ini)中删除某个数值

                MsgBox(1, "", $qq)

        
                _GUICtrlListView_DeleteAllItems($ListView1);清空 ListView1
                
                add_list() ;读取 ListView1
EndFunc   ;==>Button2()
        
        
        
        
        

config.ini

[进程]
病毒.exe=

[进程2]
1=病毒.exe

本帖子中包含更多资源

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

×
 楼主| 发表于 2009-7-22 04:04:24 | 显示全部楼层
本人很笨的。看懂了点点的 列表框 List.au3

可是还是不会做ListView列表框,恳求各位大哥大姐再帮帮小弟,小弟无比感激各位啦
发表于 2009-7-22 15:45:10 | 显示全部楼层
本帖最后由 水木子 于 2009-7-22 15:49 编辑
本人很笨的。看懂了点点的 列表框 List.au3

可是还是不会做ListView列表框,恳求各位大哥大姐再帮帮小弟,小弟无比感激各位啦
116154801 发表于 2009-7-22 04:04


示范代码都给出来了,而且每一条都加了注释,这样都还不懂的话,只能说明你前面的根基没有打好,不妨先学习前面的吧!“走都不会,如何跑呢”你说是不是?多看看相关资料和帮助吧!多琢磨琢磨别人给你的帮助代码,弄清楚每一条“为什么要这样写,这样写有什么好处,有没有其他更好的方法”这样才能有进步。
各人学习经验!学习不是一天两天的事,慢慢来切莫操之过急,万丈高楼平地起。
发表于 2009-8-14 20:18:42 | 显示全部楼层
学习学习。
发表于 2009-8-15 09:49:38 | 显示全部楼层
专程学习上面高人的代码。顶一下。
发表于 2009-11-14 15:56:01 | 显示全部楼层
都是删除指定的值,我想获得光标激活的那一项的值要怎么做?
发表于 2010-5-29 16:53:32 | 显示全部楼层
学习了`~我现在正在学习列表框的运用呢
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-22 06:52 , Processed in 0.088249 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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