#NoTrayIcon #include-once #include #include #include #include #include Local $key1 = "HKCU\Control Panel\Desktop", $key2 = "HKCU\Control Panel\Colors" Local $val1 = "Wallpaper", $val2 = "Background", $hDLL = "user32.dll" Local $wP = RegRead($key1,$val1), $bG = RegRead($key2,$val2) Local $tBar = "[CLASS:Shell_TrayWnd]", $pMan = ControlGetHandle("Program Manager","",1) Local $dt_W = @DesktopWidth, $dt_H = @DesktopHeight Local $bGcolor = 0x000000, $tpValue = 0, $wlPaper = "", $windLst = "#m" Local $style = 0x80000000, $fPath, $fRead, $wFile ;Create full screen window to prevent right click desktop context menu. Local $iGUI = GUICreate("", $dt_W+10, $dt_H+10, -1, -1, $style) GuiSetState() WinSetTrans($iGUI, "", 1) ;Make window invisible. ;Get list of folder(s) plus level one sub folders. ;The function collects the folders in alphabetical order. Local $iFold = _FileListToArrayRec(@ScriptDir, "*", 2, -1, 1) If @error Then MsgBox(0,"Error","Error retrieving folders.") Exit EndIf ;File format: The folder name followed by the image file number position. ;A comma is used as the delimiter. Local $tPath = @ScriptDir & "\" & "Temp.txt" Local $nPath = @ScriptDir & "\" & "ImagePosition.txt" Local $nFile = FileOpen($nPath) If @error = -1 Then MsgBox(0,"Error","Unable to open file.") Exit EndIf ;Ensure folder names are alphabetical in "ImagePosition.txt" _FileSortLines($nPath, $tPath) FileCopy($tPath, $nPath, 1) Local $gHWnd, $gHWnd_, $iWidth_ = 0, $iHeight_ = 0, $FrBk = 1, $hImage Local $sColors[2], $nFold = $iFold[0], $rFold, $Btn[$iFold[0]+1] Local $ff, $CT = 0, $sOne = 0, $fPos, $fList, $nList, $LineCnt ;Check for missing folders and invalid data. $LineCnt = _FileCountLines($nPath) If $LineCnt = 0 OR $LineCnt <> $nFold Then _Reset() For $i = 1 To $LineCnt $rFold = StringSplit(FileReadLine($nFile), ",") If @error OR StringIsDigit($rFold[2]) = 0 Then ExitLoop For $j = 1 To $nFold If StringCompare($rFold[1], $iFold[$j], 1) = 0 Then $CT += 1 Next Next If $CT <> $nFold Then _Reset() _GDIPlus_Startup() If $nFold = 1 Then ;Single folder $sOne = 1 $fPos = 1 $fPath = $iFold[1] $fList = _FileListToArray($fPath) $nList = $fList[0] Else ;Set GUI window height and width based on number of folders. Local $iMsg, $x, $y = 25, $iNum = $nFold, $nFac, $fPass = 0, $cInfo, $bTxt Local $wSize[7] = ["", "", 262, 377, 492, 607, 722] Local $canBtn[7] = ["", "", 95, 150, 210, 265, 325] Local $iCont[7] = ["", 25, 140, 255, 370, 485, 600] If $iNum <= 20 Then $nFac = 2 If $iNum > 20 AND $iNum <= 40 Then $nFac = 3 If $iNum > 40 AND $iNum <= 60 Then $nFac = 4 If $iNum > 60 AND $iNum <= 80 Then $nFac = 5 If $iNum > 80 Then $nFac = 6 StringSplit(String($iNum/$nFac), ".") ;Always round up number If NOT @error Then $iNum += 1 Local $hSize = (($iNum/$nFac)*35)+85, $Count = 0 If $hSize >= $dt_H Then MsgBox(0,"Error","GUI Window too large for Screen.") Exit EndIf Local $hGUI = GUICreate("", $wSize[$nFac], $hSize, -1,-1, 0x00C00000, 0x00000200) For $i = 1 To $nFold ;Create folder buttons $Count += 1 For $j = 1 To $nFac If $Count = $j Then $x = $iCont[$j] Next If $Count = $nFac Then $Count = 0 If $i > $nFac AND $x = 25 Then $y += 35 $Btn[$i] = GUICtrlCreateButton($iFold[$i], $x, $y, 100, 25) Next $Btn[0] = GUICtrlCreateButton("Cancel", $canBtn[$nFac], $hSize-45, 75, 25, 0x0001) ;Setup window title bar color. Local $aElements[2] = [2, 27], $aColors[2] = [Dec("ffff00"), Dec("00ffff")] $sColors[0] = _WinAPI_GetSysColor($aElements[0]) $sColors[1] = _WinAPI_GetSysColor($aElements[1]) DllCall("UxTheme.dll", "int", "SetWindowTheme","hwnd",$hGUI,"wstr",0,"wstr",0) _WinAPI_SetSysColors($aElements, $aColors) _SelectFolder() $fPath = $iFold[$fPos] $fList = _FileListToArray($fPath) If @error Then MsgBox(0,"Error","No files found in folder.") If $fPass Then _SelectAgain() Else _EndProgram() EndIf EndIf $nList = $fList[0] _CheckFolder() FileClose($nFile) $fPass = 1 EndIf _HideShowTask(1) _DisplayImage() ;====================================== FUNCTIONS ===================================== Func _FileSortLines($hFileIn, $hFileOut) Local $sReadFile = FileRead($hFileIn), $sWrite, $aLines Local $avArray = StringSplit(StringStripCR($sReadFile), @LF) _ArraySort($avArray, 0, 1) For $i = 1 To $avArray[0] $sWrite &= $avArray[$i] & @CRLF Next FileClose(FileOpen($hFileOut, 2)) FileWrite($hFileOut, StringTrimRight($sWrite, StringLen(@CRLF))) ;Descending order creates an unwanted blank first line when sorting. _FileReadToArray($hFileOut, $aLines) ;Delete blank line(s). For $i = $aLines[0] To 1 Step -1 If $aLines[$i] = "" Then _ArrayDelete($aLines, $i) EndIf Next _FileWriteFromArray($hFileOut, $aLines, 1) Return $hFileOut EndFunc Func _SelectFolder() GUISetState(@SW_SHOW, $hGUI) While 1 WinActivate($hGUI) ToolTip("") $iMsg = GUIGetMsg() $cInfo = GUIGetCursorInfo() If NOT @error Then $bTxt = GUICtrlRead($cInfo[4]) If StringLen($bTxt) > 18 Then ToolTip($bTxt) EndIf For $i = 0 To $nFold If $iMsg = $Btn[$i] Then $fPos = $i If $fPos > 0 Then ExitLoop 2 _EndProgram() ElseIf _IsPressed("1B", $hDLL) Then Sleep(250) _EndProgram() EndIf Next WEnd ToolTip("") GUISetState(@SW_HIDE, $hGUI) EndFunc Func _CheckFolder() Global $FD = 0 For $i = 1 To $nList $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$i]) If NOT @error Then $FD = 1 ExitLoop EndIf Next If $FD = 0 Then MsgBox(0,"Error","No images found in folder.") If $fPass Then _SelectAgain() Else _EndProgram() EndIf EndIf EndFunc Func _SelectAgain() If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_) If $FD Then _Fade($gHWnd, 255, 0, -2, 10) _SelectFolder() $fPath = $iFold[$fPos] $fList = _FileListToArray($fPath) $nList = $fList[0] _CheckFolder() _DisplayImage() EndFunc Func _DisplayImage() $rFold = StringSplit(FileReadLine(FileOpen($nPath), $fPos), ",") Global $fNum = $rFold[2] -1 If $fNum < 0 OR $fNum > $nList Then $fNum = 0 While 1 If $FrBk Then If $fNum = $nList Then $fNum = 0 $fNum += 1 Else $fNum -= 1 If $fNum = 0 Then $fNum = $nList EndIf ;Display the image/picture. $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$fNum]) If NOT @error Then _Images($hImage) WEnd EndFunc Func _Images($hImage) Local $iWidth = _GDIPlus_ImageGetWidth($hImage) Local $iHeight = _GDIPlus_ImageGetHeight($hImage) If $iHeight > $dt_H Then $ff = $iHeight/$dt_H If ($iWidth/$ff) > $dt_W Then $ff = $iWidth/$dt_W $iWidth = $iWidth/$ff $iHeight = $iHeight/$ff Else $ff = $dt_H/$iHeight If ($iWidth*$ff) > $dt_W Then $ff = $dt_W/$iWidth $iWidth = $iWidth*$ff $iHeight = $iHeight*$ff EndIf ;Create window as place holder for the image/picture. If $iWidth < $iWidth_ OR $iHeight < $iHeight_ Then _Fade($gHWnd_, 254, 0, -5, 10) $gHWnd = GUICreate("", $iWidth, $iHeight, -1, -1, $style) GUISetState() WinSetTrans($gHWnd, "", 0) Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($gHWnd) _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight) _Fade($gHWnd, 0, 255, 1, 10) _Sleep(4000) If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_) $gHWnd_ = $gHWnd $iWidth_ = $iWidth $iHeight_ = $iHeight EndFunc Func _Sleep($delay) Local $tDelay = TimerInit() While TimerDiff($tDelay) < $delay If _IsPressed("01", $hDLL) OR _IsPressed("1B", $hDLL) Then Sleep(250) If $sOne Then _EndProgram() Else _UpDate() _SelectAgain() EndIf ElseIf _IsPressed("06", $hDLL) Then ;Next Task Sleep(250) $FrBk = 1 ElseIf _IsPressed("05", $hDLL) Then ;Previous Task Sleep(250) $FrBk = 0 ElseIf _IsPressed("02", $hDLL) Then ;Right Mouse Key Sleep(250) _Pause() ;Pause Program EndIf WEnd EndFunc Func _Pause() ;Create window with button. GUICreate("", 0, 0, 0, 0, $style) ;Used as blocking function. GUICtrlCreateButton("", 0, 0) ;NOTE: window and button have no size? ;But, it works. Strange? While 1 If _IsPressed("02", $hDLL) Then ;Continue Program Sleep(250) GUIDelete() ;Delete the invisible window ExitLoop EndIf WEnd EndFunc Func _HideShowTask($hst) If NOT $hst Then $bGcolor = $bG $tpValue = 255 $wlPaper = $wP $windLst = "#+m" EndIf RegWrite($key1, $val1, "REG_SZ", $wlPaper) ;Hide/Show wallpaper DllCall($hDLL,"int","SystemParametersInfo","int",20,"int",0,"str",$wlPaper,"int",0) RegWrite($key2, $val2, "REG_SZ", $bGcolor) ;Set/Get background color WinSetTrans($tBar, "", $tpValue) ;Hide/Show taskbar WinSetTrans($pMan, "", $tpValue) ;Hide/Show desktop icons Send($windLst) ;Hide/Show windows MouseMove($dt_W/2, $dt_H-60, 0) EndFunc Func _Fade($fhand, $v1, $v2, $v3, $v4) For $i = $v1 To $v2 Step $v3 WinSetTrans($fhand, "", $i) _Sleep($v4) Next EndFunc Func _Reset() FileClose($nFile) $nFile = FileOpen($nPath, 2) For $i = 1 To $nFold FileWriteLine($nFile, $iFold[$i] & ",1") Next EndFunc Func _UpDate() $fRead = FileOpen($nPath) $wFile = FileOpen($nPath, 2) For $i = 1 To $nFold $rFold = StringSplit(FileReadLine($fRead), ",") If $i = $fPos Then FileWriteLine($wFile, $rFold[1] & "," & $fNum) Else FileWriteLine($wFile, $rFold[1] & "," & $rFold[2]) EndIf Next FileClose($wFile) FileClose($fRead) EndFunc Func _EndProgram() _HideShowTask(0) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() GuiDelete($iGUI) GUIDelete($gHWnd) FileClose($nFile) DllClose($hDLL) If $sOne Then If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_) _Fade($gHWnd, 254, 0, -2, 10) $nFile = FileOpen($nPath, 2) FileWrite($nFile, $iFold[1] & "," & $fNum) FileClose($nFile) Else _WinAPI_SetSysColors($aElements, $sColors) GUIDelete($hGUI) FileDelete($tPath) EndIf MouseClick("", $dt_W/2, $dt_H-60, 2) Exit EndFunc