116154801 发表于 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                                                ;循环
               
                GUICtrlCreateListViewItem($var_S[$n] & "|" & $var_S[$n] , $ListView1)        ;在GUI上创建一个ListView项目控件
               
        Next
               
EndFunc   ;==>add_list()


Func Button1();添加一个ListView1

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

        For $n = 1 To $var_S                                                ;循环
               
        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
各位帮帮忙。本人写了一下的源码,现在只会做到读和写,
可是修改和删除就不会弄,。
请各位帮帮忙

lynfr8 发表于 2009-7-20 21:23:01

Func Button3()      
_GUICtrlListView_DeleteItemsSelected($ListView1)               
EndFunc   ;==>Button2()上面只删除列表显示的
还要inidelete相关项
自己写写吧

lynfr8 发表于 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
                        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
                        If IniRead($dir, $var[$i], "zh", "Not Found") = GUICtrlRead($List1) Then
                              IniDelete($dir, $var[$i])
                              ;MsgBox(0, 0, "删除成功")
                              refresh()
                        EndIf
                Next
      EndIf
EndFunc   ;==>del

menfan 发表于 2009-7-21 18:31:27

学习一下。。

116154801 发表于 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
                        GUICtrlSetData($List1, $var[$i])
                                                ;修改指定控件的数据.从某标准配置文件(*.ini)中读取某个数值.

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

EndFunc   ;==>refresh

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

                For $i = 0 To $var                                                ;循环
               
                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
                        If $var[$i] = GUICtrlRead($List1) Then         ;If 从没标准配置文件(*.ini)中读取某个数值. =等于读取制定控件的状态或相关数据Then
                              IniDelete($dir, "进程" ,$var[$i])      ;从某标准配置文件(*..ini)中删除某个数值
                              MsgBox(0, 0, $var[$i])
                              refresh()
                        EndIf
                Next
      EndIf
EndFunc   ;==>del
      
      
Func del1();删除 留空的 = 号
                $var = IniReadSection($dir, "进程")   ;从某标准配置文件(*.ini)中读取所有字段的信息.
      If @error Then
                MsgBox(4096, "", "发生错误,可能目标文件并非标准的INI文件.")
      Else
                For $i = 1 To $var
                        If $var[$i] = "" Then         ;If 从没标准配置文件(*.ini)中读取某个数值. =等于读取制定控件的状态或相关数据Then
                              IniDelete($dir, "进程" ,$var[$i])      ;从某标准配置文件(*..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                                                ;循环
               
                GUICtrlCreateListViewItem($var_S[$n] & "|" & $var_S[$n] , $ListView1)      ;在GUI上创建一个ListView项目控件
               
      Next
               
EndFunc   ;==>add_list()


Func Button1();添加一个ListView1

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

      For $n = 0 To $var_S                                                ;循环
               
      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                                                ;循环
               
      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

116154801 发表于 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 http://www.autoitx.com/images/common/back.gif

示范代码都给出来了,而且每一条都加了注释,这样都还不懂的话,只能说明你前面的根基没有打好,不妨先学习前面的吧!“走都不会,如何跑呢”你说是不是?多看看相关资料和帮助吧!多琢磨琢磨别人给你的帮助代码,弄清楚每一条“为什么要这样写,这样写有什么好处,有没有其他更好的方法”这样才能有进步。
各人学习经验!学习不是一天两天的事,慢慢来切莫操之过急,万丈高楼平地起。

songtao 发表于 2009-8-14 20:18:42

学习学习。

KLU3K 发表于 2009-8-15 09:49:38

专程学习上面高人的代码。顶一下。

sonny 发表于 2009-11-14 15:56:01

都是删除指定的值,我想获得光标激活的那一项的值要怎么做?

ssfnpyu 发表于 2010-5-29 16:53:32

学习了`~我现在正在学习列表框的运用呢:face (5):
页: [1]
查看完整版本: 列表框 读+写+删+修改