#include <WindowsConstants.au3>
Global $IniFile = @ScriptDir & "\Config.ini"
$var = _IniReaNames($IniFile)
If @error Then Exit MsgBox(48, "出错!", "发生错误,INI文件读取失败!") ;INI文件读取错误将退出
Dim $iChange = 10, $dqyc = 1 ;$iChange 每页显示多少个项目;$dqyc 为当前页次
Dim $zys = Ceiling($var[0][0] / $iChange)
Global $var[20][3]
GUICreate("Label分页显示", 400, 450)
$Button1 = GUICtrlCreateButton("<", 110, 400, 30, 22)
$Button2 = GUICtrlCreateButton(">", 190, 400, 30, 22)
$Label = GUICtrlCreateLabel('1', 143, 405, 18, 17, 0x0002)
GUICtrlCreateLabel('/' & $zys, 162, 405, 23, 17)
$Button3 = GUICtrlCreateButton("返回首页", 30, 400, 80, 22)
$Button4 = GUICtrlCreateButton("跳至尾页", 220, 400, 80, 22)
$Combo = GUICtrlCreateCombo('', 305, 402, 60, 22)
$Combodata = ''
For $i = 1 To $zys
$Combodata &= '第' & $i & '页|'
Next
GUICtrlSetData(-1, $Combodata, '第1页')
GUISetState()
Go(1) ;首次读取
Go($dqyc + 2)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $Button1 ;上一页
Go($dqyc - 1)
Case $Button2 ;下一页
Go($dqyc + 1)
Case $Button3 ;首页
Go(1)
Case $Button4 ;尾页
Go($zys)
Case $Combo ;下拉选择页次
Go(StringRegExpReplace(GUICtrlRead($Combo), '[^\d]', ''))
EndSwitch
WEnd
Func Go($yc)
Local $iNo1 = ($yc - 1) * $iChange + 1
Local $iNo2
If $yc = $zys Then
$iNo2 = $var[0][0]
SetState(64, 128, 64, 128)
ElseIf $yc = 1 Then
$iNo2 = $iNo1 + $iChange - 1
SetState(128, 64, 128, 64)
Else
$iNo2 = $iNo1 + $iChange - 1
SetState(64, 64, 64, 64)
EndIf
Read($iNo1, $iNo2)
GUICtrlSetData($Label, $yc)
GUICtrlSetData($Combo, '第' & $yc & '页')
$dqyc = $yc
EndFunc ;==>Go
Func SetState($1, $2, $3, $4)
GUICtrlSetState($Button1, $1)
GUICtrlSetState($Button2, $2)
GUICtrlSetState($Button3, $3)
GUICtrlSetState($Button4, $4)
EndFunc ;==>SetState
Func Read($iNo1, $iNo2)
$var = _IniReaNames($IniFile)
Local $s = 1
For $i = $iNo1 To $iNo2
GUICtrlCreateLabel($i & '、 ' & $var[$i][1], 45, 10 + $s * 30, 130, 28)
$s += 1
Next
EndFunc ;==>Read
Func _IniReaNames($IniFile)
Local Const $N = 2
Local $var[1][$N], $p = 1
Local $i = 1
While 1
Local $ClsName = IniRead($IniFile, $i, "test", "")
If $ClsName = "" Then ExitLoop
ReDim $var[$p + 1][$N]
$var[$p][1] = IniRead($IniFile, $i, "test", "")
$p += 1
$i += 1
WEnd
$var[0][0] = UBound($var, 1) - 1
Return $var
EndFunc ;==>_IniReaNames
|