#include <GuiListView.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Dim $ListView1, $dir, $z, $Label4, $Input1, $Input2
_11()
Func _11()
$dir = @ScriptDir & "\config.ini"
$Form1 = GUICreate("列表框操作", 280, 270)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$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
EndFunc ;==>_11
Func WM_NOTIFY($hWndGUI, $MsgID, $WParam, $LParam)
Local $tagNMHDR, $Event, $hWndFrom, $IDFrom
Local $tagNMHDR = DllStructCreate("int;int;int", $LParam)
If @error Then Return $GUI_RUNDEFMSG
$IDFrom = DllStructGetData($tagNMHDR, 2)
$Event = DllStructGetData($tagNMHDR, 3)
$tagNMHDR = 0
Switch $IDFrom;选择产生事件的控件
Case $ListView1
Switch $Event; 选择产生的事件
Case $NM_CLICK ; 左击
$a = _GUICtrlListView_GetSelectedIndices($ListView1)
$b = _GUICtrlListView_GetItemTextString($ListView1, Number($a))
$c = StringSplit($b, "|")
GUICtrlSetData($Input1, $c[1])
GUICtrlSetData($Input2, $c[2])
Case $NM_DBLCLK ; 双击
Case $NM_RCLICK ; 右击
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
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 ;==>Read
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 ;==>tian