找回密码
 加入
搜索
查看: 1642|回复: 3

右键删除INI数据

[复制链接]
发表于 2009-12-26 14:35:10 | 显示全部楼层 |阅读模式
本帖最后由 lin0308 于 2009-12-26 20:20 编辑

[code#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)
$ListView = GUICtrlCreateListView("程序             |备注           |", 10, 10, 260, 150)
$lhz = GUICtrlCreateContextMenu($ListView)
$su = GUICtrlCreateMenuItem("删除数据", $lhz)
GUICtrlCreateMenuItem("", $lhz)   
$exit = GUICtrlCreateMenuItem("关闭程序", $lhz)
$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()
                                Case $exit
                                                Exit
        EndSwitch
WEnd

Func Read()
        $z = 0
        _GUICtrlListView_DeleteAllItems($ListView)
        $read = IniReadSection($dir,"chengxu")
        If Not @error Then
                For $i = 1 To $read[0][0]
                        GUICtrlCreateListViewItem($read[$i][0], $ListView)
                        _GUICtrlListView_AddSubItem($ListView, $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,"chengxu",$a,$b)
                MsgBox(0,"提示"," 程序: "&$a&" 备注: "&$b&" 保存成功 ")
                Read()
                GUICtrlSetData($Input1,"")
                GUICtrlSetData($Input2,"")
        EndIf        
EndFunc        ][/code]


比如INI文件内容是

[chengxu]
PPStream.exe=pps
KwMusic.exe=酷我
KuGoo.exe=酷狗
QvodPlayer.exe=快播


如何右键删除其中一个数据呢?

水木子的例子是不错,可是看不大懂,寻求比较简单的的例子,后用上面代码修改,谢谢

本帖子中包含更多资源

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

×

评分

参与人数 1金钱 +10 收起 理由
pusofalse + 10 感谢主动修改帖子分类为[已解决]。

查看全部评分

发表于 2009-12-26 14:55:19 | 显示全部楼层
本帖最后由 水木子 于 2009-12-26 14:57 编辑

LZ的代码好眼熟!
看看这贴6楼的代码吧!我记得好像有。
http://www.autoitx.com/forum.php ... mp;page=1#pid108344

评分

参与人数 1金钱 +10 贡献 +2 收起 理由
lin0308 + 10 + 2 十分感谢,

查看全部评分

发表于 2009-12-26 20:26:43 | 显示全部楼层
本帖最后由 水木子 于 2009-12-26 20:30 编辑

那段代码太长?不方便阅读?
我整理了下,看看吧!
#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
Opt("TrayMenuMode", 1)
$dir = @ScriptDir&"\config.ini"

GUICreate("列表框操作", 280, 270)
$ListView1 = GUICtrlCreateListView("账号           |密码           |", 10, 10, 260, 150)
$But1 = GUICtrlCreateButton("添加", 185, 178, 75, 25, $WS_GROUP)
$Input1 = GUICtrlCreateInput("", 60, 180, 120, 21)
$Input2 = GUICtrlCreateInput("", 60, 220, 120, 21)
GUICtrlCreateLabel("账号:", 20, 183, 36, 17)
GUICtrlCreateLabel("密码:", 20, 223, 36, 17)
GUICtrlCreateLabel("数据", 200, 223, 36, 17)
$Label1 = GUICtrlCreateLabel("0", 230, 223, 36, 17)

;右键菜单
$zhucaidan = GUICtrlCreateContextMenu($ListView1)
$add = GUICtrlCreateMenuItem("添加数据", $zhucaidan)
GUICtrlCreateMenuItem("", $zhucaidan)
$del = GUICtrlCreateMenuItem("删除数据", $zhucaidan)
GUICtrlCreateMenuItem("", $zhucaidan)
$break = GUICtrlCreateMenuItem("刷新数据", $zhucaidan)
GUISetState(@SW_SHOW)
Read()

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case -3
                        Exit
                Case $But1,$add
                        Add()
                Case $del
                        Del()
                Case $break
                        Read()
        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($Label1,$z+1)
                        $z += 1                
                Next
        EndIf
EndFunc

Func Add()
        $a = GUICtrlRead($Input1)
        $b = GUICtrlRead($Input2)                
        $z = GUICtrlRead($Label1)
        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($Label1,$z+1)
                GUICtrlSetState($Input1, $GUI_FOCUS)
        EndIf        
EndFunc        

Func Del()
        $a = _GUICtrlListView_GetSelectedIndices($ListView1)
        $b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
        $chaifen = StringSplit($b,"|")
        $a = MsgBox(32+1,"提示","请确认是否删除以下数据"&@CRLF&@CRLF&"账号:"&$chaifen[1]&@CRLF&@CRLF&"密码:"&$chaifen[2])
        If $a = 1 Then
                _GUICtrlListView_DeleteItemsSelected($ListView1) ;删除选定项目
                IniDelete ($dir,'config', $chaifen[1])
                $z = _GUICtrlListView_GetItemCount($ListView1)
                GUICtrlSetData($Label1, $z)                
                ;MsgBox(48, "提示", "数据删除成功")
        EndIf        
EndFunc        
发表于 2012-2-5 17:31:13 | 显示全部楼层
有时间研究一下。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 23:26 , Processed in 0.096888 second(s), 26 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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