[已解决]ini排序问题
本帖最后由 jycel 于 2010-4-14 12:52 编辑INI配置中,键名是一个一个写入的,全是计算名,值是IP地址 ,当上线一个机器就会写入
要处理的就是对键名按计算机名从小到大排序,麻烦大家给点意见!
格式如下:
[在线用户]
PC090=192.168.0.100
PC094=192.168.0.104
PC029=192.168.0.39
PC001=192.168.0.11
PC017=192.168.0.27
测试代码如下:
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#include <GuiConstantsEx.au3>
$user=@ScriptDir&"\user.ini"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 198, 352, 192, 114)
$ListView1 = GUICtrlCreateListView("", 16, 8, 161, 281, $WS_BORDER,$LVS_ICON)
GUICtrlSetBkColor(-1, 0x3A6EA5)
_GUICtrlListView_SetView($ListView1, 3);设置样式,可选(1、2、3、4)
$Button1 = GUICtrlCreateButton("排序", 8, 304, 169, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_duuser()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
EndSwitch
WEnd
Func _duuser()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
$var=IniReadSection($user,"在线用户")
If Not @error Then
For $i= 1 To $var
GUICtrlCreateListViewItem($var[$i], $ListView1)
GUICtrlSetImage(-1,"shell32.dll",-19)
Next
EndIf
EndFunc
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <GuiConstantsEx.au3>
#include <Array.au3>
$user = @ScriptDir & "\user.ini"
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 198, 352, 192, 114)
$ListView1 = GUICtrlCreateListView("", 16, 8, 161, 281, $WS_BORDER, $LVS_ICON)
GUICtrlSetBkColor(-1, 0x3A6EA5)
_GUICtrlListView_SetView($ListView1, 3);设置样式,可选(1、2、3、4)
$Button1 = GUICtrlCreateButton("排序", 8, 304, 169, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_duuser()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Sort()
EndSwitch
WEnd
Func Sort()
$var = IniReadSection($user, "在线用户")
_ArraySort($var, 0, 1)
IniWriteSection($user, "在线用户", $var)
_duuser()
EndFunc ;==>Sort
Func _duuser()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
$var = IniReadSection($user, "在线用户")
If Not @error Then
For $i = 1 To $var
GUICtrlCreateListViewItem($var[$i], $ListView1)
GUICtrlSetImage(-1, "shell32.dll", -19)
Next
EndIf
EndFunc ;==>_duuser 学习了!谢谢afan :face (1):太好了,刚好用上 很好,留个记号!
页:
[1]