如何让软件菜单分上下页且指定数量显示!
如图,如何让其指定数量分成上下页读取!例:只能显示2个,我按下一页读下2个,我按上一页读上2个! 本帖最后由 shqf 于 2014-9-26 13:55 编辑
方法很多,以下是我常用的一种。
game.ini配置要如下:
path=D:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe
page=1
path=D:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe
page=1
path=D:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe
page=2
path=D:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe
page=2
path=D:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe
page=3
path=D:\Program Files\Tencent\QQ\QQProtect\Bin\QQProtect.exe
page=3
脚本代码如下:
#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
If Not FileExists(@ScriptDir & "\game.ini") Then
MsgBox(0, "", "缺少本文件game.ini文件有误")
Exit
Else
Global $var = IniReadSectionNames(@ScriptDir & "\game.ini") ;读取文件信息
If @error Then
MsgBox(4096, "提示", "读取INI文件出错!")
Exit
EndIf
EndIf
Local $page = 1
$Form1_1 = GUICreate("菜单", 782, 560, 192, 114, BitOR($WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_CAPTION, _
$WS_POPUP, $WS_POPUPWINDOW, $WS_GROUP, $WS_TABSTOP, $WS_BORDER, $WS_CLIPSIBLINGS))
$ListView1 = GUICtrlCreateListView("", 0, 0, 500, 400)
GUICtrlSetBkColor(-1, 0x008000)
GUICtrlSetStyle(-1, $LVS_ICON)
$PageUp = GUICtrlCreateButton("上一页", 600, 56, 80, 25)
$PageDown = GUICtrlCreateButton("下一页", 600, 100, 80, 25)
GUISetState(@SW_SHOW)
_Load(1) ;listview显示第一页项目
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $PageUp
If $page = 1 Then
MsgBox(0, "", "已到第一页")
Else
$page -= 1
_Load($page)
EndIf
Case $PageDown
If $page = 3 Then
MsgBox(0, "", "已到最后一页")
Else
$page += 1
_Load($page)
EndIf
EndSwitch
WEnd
Func _Load($npage);
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListView1))
For $i = 1 To $var
$path = IniReadSection(@ScriptDir & "\game.ini", String($var[$i]));读取配置
If $path = $npage Then
If FileExists($path) Then;检查路径是否正确
$hImage = _GUIImageList_Create(32, 32, 5, 1) ;图标显示大小
_GUIImageList_AddIcon($hImage, $path, 0, True) ;$himage为包含所需图像的图标
_GUICtrlListView_SetImageList($ListView1, $hImage, 0);将控件的图像列表
_GUICtrlListView_InsertItem($ListView1, $var[$i], -1, 0) ;列表的末尾添加一个新的项目
Else
MsgBox(0, "警警!!", "ini文件有误");路径不正确时提示
Exit
EndIf
EndIf
Next
EndFunc ;==>_Load 回复 2# shqf
这个思路非常不错! 回复 2# shqf
那顺便问句,我如何获取到ini中 page=1 ,=1的数量有多少,等于2的数量有多少?? #include <Array.au3>
#include <WinAPI.au3>
#include <GDIPlus.au3>
#include "GUICtrlOnHover.au3"
Opt("GUIOnEventMode", 1)
Local $PicPath = @WindowsDir & "\Web\Wallpaper\"
Local $dqpage = 1, $zjpage = 1, $pic, $comboread, $ctrlidgraphic, $ctrlid, $hGUI
#Region ### START Koda GUI section ### Form=
Local $Form1 = GUICreate("Form1", 600, 400, -1, -1, -1, -1, WinGetHandle(AutoItWinGetTitle()))
GUISetOnEvent(-3, "GuiClick")
Local $Button1 = GUICtrlCreateButton("上一页", 20, 360, 130, 30)
GUICtrlSetOnEvent(-1, "GuiClick")
GUICtrlSetState(-1, 128)
Local $Button2 = GUICtrlCreateButton("下一页", 180, 360, 130, 30)
GUICtrlSetOnEvent(-1, "GuiClick")
GUICtrlSetState(-1, 128)
Local $Label1 = GUICtrlCreateLabel("当前是第" & $dqpage & "页,共计" & $zjpage & "页,每页显示", 340, 370, 200, 17)
GUICtrlSetOnEvent(-1, "GuiClick")
Local $Combo1 = GUICtrlCreateCombo("", 540, 365, 40, 20, 0x0003)
GUICtrlSetData(-1, "1|4|9|16|100", 9)
GUICtrlSetOnEvent(-1, "GuiClick")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $PicList = PicRead($PicPath)
;~ $PicList = 30
;~ ReDim $PicList
If Not @error Then
PicCreate()
PicShow()
EndIf
While 1
Sleep(100)
WEnd
Func GuiClick()
Switch @GUI_CtrlId
Case -3
Exit
Case $Button1
$dqpage -= 1
GUICtrlSetState($Button1, 128)
GUICtrlSetState($Button2, 128)
PicShow()
Case $Button2
$dqpage += 1
GUICtrlSetState($Button1, 128)
GUICtrlSetState($Button2, 128)
PicShow()
Case $Combo1
PicCreate()
PicShow()
EndSwitch
EndFunc ;==>GuiClick
Func PicRead($sDir)
If StringInStr(FileGetAttrib($sDir), "D") = 0 Then Return SetError(1, 0, "")
Local $oFSO = ObjCreate("Scripting.FileSystemObject")
Local $objDir
Local $aDir = StringSplit($sDir, "|", 2)
Local $iCnt = 0
Local $sFiles = ""
Do
$objDir = $oFSO.GetFolder($aDir[$iCnt])
For $aItem In $objDir.SubFolders
$sDir &= "|" & $aItem.Path
Next
For $aItem In $objDir.Files
If StringRight($aItem.Path, 3) = "jpg" Then $sFiles &= $aItem.Path & "|"
Next
$iCnt += 1
If UBound($aDir) <= $iCnt Then $aDir = StringSplit($sDir, "|", 2)
Until UBound($aDir) <= $iCnt
Return StringSplit(StringTrimRight($sFiles, 1), "|")
EndFunc ;==>PicRead
Func PicCreate()
If $comboread = GUICtrlRead($Combo1) Then Return
$comboread = GUICtrlRead($Combo1)
For $i = 0 To UBound($pic) - 1
GUICtrlDelete($pic[$i])
Next
ReDim $pic
ReDim $pic[$comboread]
$dqpage = 1
$zjpage = Ceiling($PicList / $comboread)
For $i = 0 To $comboread - 1
$pic[$i] = GUICtrlCreatePic("", 20 * (Mod($i, Sqrt($comboread)) + 1) + Mod($i, Sqrt($comboread)) * (560 - 20 * Sqrt($comboread)) / Sqrt($comboread), 20 * (Floor($i / Sqrt($comboread)) + 1) + Floor($i / Sqrt($comboread)) * (330 - 20 * Sqrt($comboread)) / Sqrt($comboread), (560 - 20 * Sqrt($comboread)) / Sqrt($comboread), (330 - 20 * Sqrt($comboread)) / Sqrt($comboread))
GUICtrlSetOnHover(-1, "_Hover_Func", "_Hover_Func")
Next
EndFunc ;==>PicCreate
Func PicShow()
GUICtrlSetData($Label1, "当前是第" & $dqpage & "页,共计" & $zjpage & "页,每页显示")
For $i = 0 To $comboread - 1
If $i + 1 + ($dqpage - 1) * $comboread < $PicList Then
GUICtrlSetImage($pic[$i], $PicList[$i + 1 + ($dqpage - 1) * $comboread])
Else
GUICtrlDelete($pic[$i])
$pic[$i] = GUICtrlCreatePic("", 20 * (Mod($i, Sqrt($comboread)) + 1) + Mod($i, Sqrt($comboread)) * (560 - 20 * Sqrt($comboread)) / Sqrt($comboread), 20 * (Floor($i / Sqrt($comboread)) + 1) + Floor($i / Sqrt($comboread)) * (330 - 20 * Sqrt($comboread)) / Sqrt($comboread), (560 - 20 * Sqrt($comboread)) / Sqrt($comboread), (330 - 20 * Sqrt($comboread)) / Sqrt($comboread))
GUICtrlSetOnHover(-1, "_Hover_Func", "_Hover_Func")
EndIf
Next
If $dqpage = 1 Then
GUICtrlSetState($Button1, 128)
If $zjpage = 1 Then
GUICtrlSetState($Button2, 128)
Else
GUICtrlSetState($Button2, 64)
EndIf
ElseIf $dqpage >= $zjpage Then
$dqpage = $zjpage
GUICtrlSetState($Button2, 128)
ElseIf $dqpage < 1 Then
$dqpage = 1
GUICtrlSetState($Button2, 64)
Return
Else
GUICtrlSetState($Button1, 64)
GUICtrlSetState($Button2, 64)
EndIf
EndFunc ;==>PicShow
Func _Hover_Func($iCtrlID, $iParam)
Local $ctrlidpos, $hStatic, $aPos, $iwidth, $iheight
If $ctrlid <> $iCtrlID Then
GUICtrlDelete($ctrlidgraphic)
If $PicList < $iCtrlID + $comboread * ($dqpage - 1) - 5 Then Return $ctrlid = ""
$ctrlid = $iCtrlID
$ctrlidpos = ControlGetPos($Form1, "", $iCtrlID)
$ctrlidgraphic = GUICtrlCreateGraphic($ctrlidpos - 1, $ctrlidpos - 1, $ctrlidpos + 2, $ctrlidpos + 2)
GUICtrlSetColor(-1, 0x00000FF)
$aPos = WinGetPos($Form1, "")
_GDIPlus_Startup()
$hImage = _GDIPlus_ImageLoadFromFile($PicList[$iCtrlID + $comboread * ($dqpage - 1) - 6])
$hHeight = _GDIPlus_ImageGetHeight($hImage)
$hWidth = _GDIPlus_ImageGetWidth($hImage)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
If $aPos + 1010 > @DesktopWidth Then
$iwidth = $aPos - 505
Else
$iwidth = $aPos + 610
EndIf
If $aPos + $hHeight * (500 / $hWidth) >= @DesktopHeight Then
Local $wpos = WinGetPos("")
$iheight = @DesktopHeight - $hHeight * (500 / $hWidth) - $wpos
Else
$iheight = $aPos
EndIf
$hGUI = GUICreate("Test", 500, $hHeight * (500 / $hWidth), $iwidth, $iheight, 0x00800000 + 0x80000000, BitOR(0x00000080, 0x00000008))
GUICtrlCreatePic("", 0, 0, 500, $hHeight * (500 / $hWidth))
GUICtrlSetImage(-1, $PicList[$iCtrlID + $comboread * ($dqpage - 1) - 6])
GUISetState(@SW_DISABLE, $hGUI)
GUISetState(@SW_SHOWNOACTIVATE, $hGUI)
ElseIf $iParam = 2 Then
GUIDelete($hGUI)
GUICtrlDelete($ctrlidgraphic)
$ctrlid = ""
EndIf
EndFunc ;==>_Hover_Func
回复 5# shenrenba
没有 GUICtrlOnHover.au3 文件 这个思路非常不错! 回复 5# shenrenba
不错,谢谢分享!! 前来学习。。。。。。。。。。。。。。。。。
页:
[1]