#include <GUIListView.au3>
Global $fIni = 'test.ini'
If Not FileExists($fIni) Then ;---- 没有测试文件就自动生成一个
Local $sData = '', $aN[6] = ['张', '李', '王', '赵', '钱', '孙'], $aAdm[2] = ['是', '否']
For $ii = 1 To 100
$sData &= '[' & $aN[Random(0, 5, 1)] & $ii & ']' & @CRLF & 'PassWord=' & Random(111111, 999999, 1) & @CRLF & 'UserMode=' & $aAdm[Random(0, 1, 1)] & @CRLF
Next
Local $hFO = FileOpen($fIni, 512 + 10)
FileWrite($hFO, $sData)
FileClose($hFO)
EndIf
Opt('GUIOnEventMode', 1)
Global $hGUI, $ListView1, $hListView1, $aItem, $iInput, $iComb
_GUICreate()
While 1
Sleep(1000)
WEnd
Func _GUICreate()
Dim $hGUI = GUICreate('Ini 数据管理', 300)
GUISetOnEvent(-3, '_Exit')
Dim $iInput = GUICtrlCreateInput('', -100, -100)
Dim $iComb = GUICtrlCreateCombo('', -100, -100, -1, -1, 3) ; $CBS_DROPDOWNLIST=0x0003
GUICtrlSetData(-1, '是|否')
Dim $ListView1 = GUICtrlCreateListView('用户名 |密码 |管理员权限|管理', 2, 20, 296, 350)
Dim $hListView1 = GUICtrlGetHandle(-1)
GUICtrlSetFont(-1, 11, 400, 0, '微软雅黑')
_LoadIni2LVW()
GUISetState()
Local $id1 = GUICtrlCreateDummy()
GUICtrlSetOnEvent(-1, '__UdpData')
Local $aAccelKeys[1][2] = [['{Enter}', $id1]]
GUISetAccelerators($aAccelKeys)
GUIRegisterMsg(0x004E, '_WM_NOTIFY') ;$WM_NOTIFY = 0x004E
EndFunc ;==>_GUICreate
Func _LoadIni2LVW()
Local $aIni = IniReadSectionNames($fIni)
If @error Then Return SetError(1, 0, 0)
Local $ii, $sPassWord, $sUserMode
For $ii = 1 To $aIni[0]
$sPassWord = IniRead($fIni, $aIni[$ii], 'PassWord', '')
$sUserMode = IniRead($fIni, $aIni[$ii], 'UserMode', '否')
GUICtrlCreateListViewItem(StringFormat('%s|%s|%s|删除', $aIni[$ii], $sPassWord, $sUserMode), $ListView1)
Next
EndFunc ;==>_LoadIni2LVW
Func __UdpData()
If Not IsArray($aItem) Then Return
Local $sRd = GUICtrlRead($aItem[2]), $sData = ''
_GUICtrlListView_SetItemText($hListView1, $aItem[0], $sRd, $aItem[1])
Switch $aItem[1]
Case 1
IniWrite($fIni, _GUICtrlListView_GetItemText($hListView1, $aItem[0]), 'PassWord', $sRd)
Case 2
IniWrite($fIni, _GUICtrlListView_GetItemText($hListView1, $aItem[0]), 'UserMode', $sRd)
EndSwitch
GUICtrlSetPos($aItem[2], -1000, -100)
Dim $aItem = 0
EndFunc ;==>__UdpData
Func _WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
If HWnd(DllStructGetData($tNMHDR, 'hWndFrom')) <> $hListView1 Then Return 'GUI_RUNDEFMSG'
Switch DllStructGetData($tNMHDR, 'Code')
Case -2 ;$NM_CLICK = -2
If IsArray($aItem) Then
__UdpData()
Else
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $iIndex = DllStructGetData($tInfo, 'Index')
Local $iSub = DllStructGetData($tInfo, 'SubItem')
If $iSub = 3 Then
Local $sName = _GUICtrlListView_GetItemText($hListView1, $iIndex)
If MsgBox(48 + 4, '确认删除', '是否删除用户 "' & $sName & '" ?', 0, $hGUI) = 6 Then
_GUICtrlListView_DeleteItem($hListView1, $iIndex)
IniDelete($fIni, $sName)
EndIf
EndIf
EndIf
Case -3 ;$NM_DBLCLK = -3
Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
Local $iIndex = DllStructGetData($tInfo, 'Index')
Local $iSub = DllStructGetData($tInfo, 'SubItem')
Dim $aItem = 0
If $iSub <> 1 And $iSub <> 2 Then Return 'GUI_RUNDEFMSG'
Local $aRect = _GUICtrlListView_GetSubItemRect($hListView1, $iIndex, $iSub)
Local $sData = _GUICtrlListView_GetItemText($hListView1, $iIndex, $iSub)
If $iSub = 1 Then
Dim $aItem[3] = [$iIndex, $iSub, $iInput]
Else
Dim $aItem[3] = [$iIndex, $iSub, $iComb]
EndIf
GUICtrlSetData($aItem[2], $sData)
GUICtrlSetPos($aItem[2], $aRect[0] + 4, $aRect[1] + 22, $aRect[2] - $aRect[0])
GUICtrlSetState($aItem[2], 256)
EndSwitch
EndFunc ;==>_WM_NOTIFY
Func _Exit()
Exit
EndFunc ;==>_Exit