#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[1], $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[0] = 30
;~ ReDim $PicList[30]
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[1]
ReDim $pic[$comboread]
$dqpage = 1
$zjpage = Ceiling($PicList[0] / $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[0] 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[0] < $iCtrlID + $comboread * ($dqpage - 1) - 5 Then Return $ctrlid = ""
$ctrlid = $iCtrlID
$ctrlidpos = ControlGetPos($Form1, "", $iCtrlID)
$ctrlidgraphic = GUICtrlCreateGraphic($ctrlidpos[0] - 1, $ctrlidpos[1] - 1, $ctrlidpos[2] + 2, $ctrlidpos[3] + 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[0] + 1010 > @DesktopWidth Then
$iwidth = $aPos[0] - 505
Else
$iwidth = $aPos[0] + 610
EndIf
If $aPos[1] + $hHeight * (500 / $hWidth) >= @DesktopHeight Then
Local $wpos = WinGetPos("[class:Shell_TrayWnd]")
$iheight = @DesktopHeight - $hHeight * (500 / $hWidth) - $wpos[3]
Else
$iheight = $aPos[1]
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