Jump to content

Timer being ignored?


Go to solution Solved by TheSaint,

Recommended Posts

I'm updating my slideshow program to use GDI+

During the process, I found that my images weren't changing.

From what I can tell... Autoit is completely ignoring the timer...

My head hurts.

Slideshow with GDI -- line 81 to 84 you can see how I'm testing

#include <File.au3>
#include <GetFileProperty.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Timers.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <GDIPlus.au3>

;Only allow one instance of the program to run.
If _Singleton("Fullscreen Slideshow", 1) = 0 Then
    Exit
EndIf

;Settings
;====================================
GetSettings()
;====================================
Global $desktop
Global $ssTimerSet = 0
Global $countedImages = 0
Global $imageWasShown = 1
Global $hidden = 0
Global $VNChidden = 0
Global $checkCount = 1
Global $taskbarActivationHide = 0
;Global $inputDirector = WinGetHandle("Cursor Hider")
;Uknown glitch fix
;$inputDirector = 0x00530C46
;======
Global $imageList = _FileListToArray($pictureFolder)
Global $imageCount = $imageList[0]
Global $imageShown[$imageCount + 1]
Global $resetCount = 0
Global $reset = 0
Global Const $STM_SETIMAGE = 0x0172
Global $currActiveWindow = WinGetHandle("")
Global $imageChangedBlack = 0
Global $imageWidth, $imageHeight, $pHeight, $pWidth, $smCenterX, $smCenterY, _
        $picName, $activeWindowPosition, $refreshImage, $imageTimer, $screenSaverTimer, _
        $startWithWindows, $closeWithScreensaver
Global $screenSaverOpened = 0
Global $winSize[2]
Global $hHBmp


_GDIPlus_Startup()

;GetMonitorInformation()
GetImage()

;GUI
;Hidden GUI for fixing if FSS becomes the active window
GUICreate("FSS", 0, 0, 0, 0)

;Parent, for taskbar hide effect
$GUIHide = GUICreate("hide", 0, 0, 0, 0)

;Actual GUI to be used
$GUI = GUICreate("Fullscreen Slideshow", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the screen
$hHBmp = $pictureFolder & "\" & $imageList[$picName]
$gdiPic = _GDIPlus_BitmapCreateFromFile($hHBmp) ;convert GDI bitmap to GDI+ bitmap
_WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
$pic = _GDIPlus_ImageResize($gdiPic, $imageWidth, $imageHeight) ;resize image
GUICtrlSetPos($pic, $smCenterX, $smCenterY)
GUISetBkColor(0)
GUISetState(@SW_SHOW)
MoveWindow()
Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI) ;create a graphics object from a window handle
_GDIPlus_GraphicsDrawImage($hGraphics, $pic, $smCenterX, $smCenterY) ;display scaled image

$imageTimer = TimerInit() ;Reset Image Change Timer
WinActivate(HWnd($currActiveWindow)) ;Activate window that was previously active

;Fix for sudden power failure (screensaver fix)
RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "ForceFSSOn", "REG_SZ", 0)

;Main Program
While 1
    ToolTip($timerSeconds * 1000, 100, 5, TimerDiff($imageTimer))
    If TimerDiff($imageTimer) > ($timerSeconds * 1000) Then
        Exit
    EndIf
    ;Debug
;~  ToolTip(CheckIfFSSshouldDisplay() & @CRLF & _
;~          "Active: " & $activeWindowPosition[0] & ", " & $activeWindowPosition[1] & @CRLF & _
;~          "Mouse: " & MouseGetPos(0) & ", " & MouseGetPos(1) & @CRLF & _
;~          "Desktop: " & $desktop & @CRLF & _
;~          "Monitor: " & @DesktopWidth & "x" & @DesktopHeight _
;~          , 100, 5)
    ;==========================
    ;ToolTip(TimerDiff($screenSaverTimer), 100, 5)

    ;Show Tray Icon?
    If $showIcon = "No" Then
        AutoItSetOption("TrayIconHide", 1)
    Else
        AutoItSetOption("TrayIconHide", 0)
    EndIf

    ;Start with Windows?
    If $startWithWindows = "Yes" Then
        If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow") = "" Then
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow", "REG_SZ", '"' & @ScriptFullPath & '"')
        EndIf
    Else
        If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow") <> "" Then
            RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow")
        EndIf
    EndIf

    ;Close program if Screensaver closes
    If $closeWithScreensaver = "Yes" Then
        If $screenSaverOpened = 1 Then
            If ProcessExists("Fullscreen Screensaver.exe") = 0 Then
                Exit
            EndIf
        EndIf
    EndIf

    ;Make sure Fullscreen Screensaver is running
    If $runScreensaver = "Yes" Then
        If ProcessExists("Fullscreen Screensaver.exe") = 0 Then
            Run("D:\Autoit Scripts\Fullscreen Screensaver.exe")
            $screenSaverOpened = 1
        Else
            $screenSaverOpened = 1
        EndIf
    EndIf

    ;Always keep FSS on top of other windows
    WinSetOnTop("Fullscreen Slideshow", "", 0)
    WinSetOnTop("Fullscreen Slideshow", "", 1)

    ;If Fullscreen Slideshow becomes the active window, change to FSS
    If WinActive("Fullscreen Slideshow", "") <> 0 Then
        WinActivate("FSS", "")
    EndIf

    ;Should Fullscreen Slideshow be on or off
    If CheckIfFSSshouldDisplay() = "Show" Then
        If $activationMode = "Inactive" Then ;Monitor not in use
            WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
        Else ;$activationMode = "Timer" (Screensaver mode)
            If TimerDiff($screenSaverTimer) > ($ssTimerSeconds * 1000) Then
                WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
            EndIf
        EndIf
    Else
        ;Skype Black Screen Glitch
        ;============
        If WinExists("[CLASS:tchatcontentcontrol]") = 1 Then
            WinClose("[CLASS:tchatcontentcontrol]")
        EndIf
        ;============
        WinSetState("Fullscreen Slideshow", "", @SW_HIDE)
        $refreshImage = 1
        $screenSaverTimer = TimerInit() ;Reset Screensaver Timer
    EndIf

    ;Changing the Image
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") <> "Monitor Off" Then
        $imageChangedBlack = 0
        If $changeMode = "Refresh" Then
            If $refreshImage = 1 Then
                $refreshImage = 0
                GetImage()
                _GDIPlus_ImageDispose($pic)
                $hHBmp = $pictureFolder & "\" & $imageList[$picName]
                $gdiPic = _GDIPlus_BitmapCreateFromFile($hHBmp) ;convert GDI bitmap to GDI+ bitmap
                _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
                $pic = _GDIPlus_ImageResize($gdiPic, $imageWidth, $imageHeight) ;resize image
                $hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI) ;create a graphics object from a window handle
                _GDIPlus_GraphicsDrawImage($hGraphics, $pic, $smCenterX, $smCenterY) ;display scaled image
            EndIf
        Else ;$changeMode = "Timer"
            If TimerDiff($imageTimer) > ($timerSeconds * 1000) Then
                GetImage()
                ;How to dispose of image?
                $hHBmp = $pictureFolder & "\" & $imageList[$picName]
                $gdiPic = _GDIPlus_BitmapCreateFromFile($hHBmp) ;convert GDI bitmap to GDI+ bitmap
                _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
                $pic = _GDIPlus_ImageResize($gdiPic, $imageWidth, $imageHeight) ;resize image
                $hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI) ;create a graphics object from a window handle
                _GDIPlus_GraphicsDrawImage($hGraphics, $pic, $smCenterX, $smCenterY) ;display scaled image
                $imageTimer = TimerInit() ;Reset Image Change Timer
            EndIf
        EndIf
    Else ;Use Black Image
        If $imageChangedBlack = 0 Then
            $imageChangedBlack = 1
            GUICtrlDelete($pic)
            $pic = GUICtrlCreatePic("D:\All Black.jpg", 0, 0, $smWidth, $smHeight)
        EndIf
    EndIf

    ;Hide/Show Taskbar
    If MouseGetPos(0) > 0 And MouseGetPos(0) < @DesktopWidth Then ;If mouse is in main monitor
        If MouseGetPos(1) > (@DesktopHeight - 2) Then ;If mouse is at bottom of screen
            ShowTaskBar()
        ElseIf MouseGetPos(1) < (@DesktopHeight - $taskbarSize) Then ;If mouse leaves taskbar area
            If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Blink Taskbar") = 0 Then HideTaskBar()
        EndIf
    Else
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Blink Taskbar") = 0 Then HideTaskBar()
    EndIf

    ;Only every 5 times
    If $checkCount > 5 Then
        $checkCount = 1
        ;Pre-cautionary in case of changes in Monitor dimensions (if secondary monitor is unplugged)
        MoveWindow()
        ;Check settings for changes
        GetSettings()
    Else
        $checkCount += 1
    EndIf

    ;Allow CPU to rest
    Sleep(100)
WEnd
_GDIPlus_Shutdown()

Func GetImage()
    Local $newPic = 0

    ;Change count, if image folder changes
    CheckForImageChanges()

    If $randomImages = "Ordered" Then
        ;Counted Images default is 0
        $countedImages += 1
        ;If the the counted images surpasses the number of images that are there, then reset the count
        If $countedImages > $imageCount Then
            $countedImages = 1
        EndIf
        $picName = $countedImages
    ElseIf $randomImages = "Random" Then
        ;Select a random image from the list
        $picName = Random(1, $imageCount, 1)
    Else ;$randomImages = "Random No Repeat"

        If $reset = 1 Then
            $reset = 0
            $resetCount = 0
            For $x = 1 To $imageCount Step +1
                $imageShown[$x] = ""
            Next
        EndIf
        While $newPic <> 1
            $picName = Random(1, $imageCount, 1) ;Pick a random image
            ;Check if image has been shown
            For $y = 1 To $imageCount Step +1
                If $picName = $imageShown[$y] Then
                    $imageWasShown = 1
                EndIf
            Next ;y
            If $imageWasShown = 1 Then
                $imageWasShown = 0
                $newPic = 0
            Else
                $newPic = 1
                $resetCount += 1
            EndIf
            If $resetCount = $imageCount Then
                $reset = 1
            EndIf
        WEnd
        ;Save image to shown image list
        ;Store name in next available empty slot
        For $x = 1 To $imageCount Step +1
            If $imageShown[$x] = "" Then
                $imageShown[$x] = $picName ;Save image to shown image list
                ExitLoop ;End loop early
            EndIf
        Next
    EndIf

    ;Get Dimensions of image
    GetDimensions($imageList[$picName])
    $imageHeight = $pHeight
    $imageWidth = $pWidth

    ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $imageWidth > $smWidth Or $imageHeight > $smHeight Then
        ;Get aspect ratio
        $aspectRatioX = $smWidth / $imageWidth ;Aspect ratio = 1280 / image X
        $aspectRatioY = $smHeight / $imageHeight ;Aspect ratio = 800 / image Y
        If $aspectRatioX < $aspectRatioY Then
            ;Image is wide
            ;New Height
            $imageHeight = $smWidth * ($imageHeight / $imageWidth)
            $imageWidth = $smWidth
        Else
            ;Image is tall
            ;New Width
            $imageWidth = $smHeight * ($imageWidth / $imageHeight)
            $imageHeight = $smHeight
        EndIf
        $imageWidth = Int($imageWidth) ;Convert iW into integer
        $imageHeight = Int($imageHeight) ;Convert iH into integer
    EndIf

    ;Calculate Center
    ;(Monitor size - image size) / 2
    $smCenterX = ($smWidth - $imageWidth) / 2
    $smCenterY = ($smHeight - $imageHeight) / 2
EndFunc   ;==>GetImage

Func GetDimensions($picName)
    Local $prop, $dArray
    $path = $pictureFolder & "\" & $picName
    $prop = _GetFileProperty($path, "Dimensions")
    $dArray = StringSplit($prop, " x ")
    $pWidth = Number(StringMid($dArray[1], 2))
    $pHeight = Number($dArray[4])
EndFunc   ;==>GetDimensions

Func MoveWindow()
    Local $position = WinGetPos("Fullscreen Slideshow")
    If $smPosition = "Left" Then
        If $position[0] <> (-1 * $smWidth) Or $position[1] <> $smHeight Then
            WinMove("Fullscreen Slideshow", "", (-1 * $smWidth), 0, $smWidth, $smHeight)
        EndIf
    Else
        If $position[0] <> @DesktopWidth Or $position[1] <> $smHeight Then
            WinMove("Fullscreen Slideshow", "", @DesktopWidth, 0, $smWidth, $smHeight)
        EndIf
    EndIf
EndFunc   ;==>MoveWindow
Func HideTaskBar()
    ControlHide('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
    ControlHide('', '', WinGetHandle("[CLASS:Button]"))
EndFunc   ;==>HideTaskBar
Func ShowTaskBar()
    ControlShow('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
    ControlShow('', '', WinGetHandle("[CLASS:Button]"))
EndFunc   ;==>ShowTaskBar

Func CheckIfFSSshouldDisplay()
    Local $decided = 0
    Local $returnValue

    ;Is selected window the Desktop?
    $winSize = WinGetClientSize("")
    If $winSize = "" Then ;Prevents non-accessible glitch
        $desktop = 0
    Else
        If $winSize[0] = @DesktopWidth + $smWidth Then ;Desktop
            $desktop = 1
        Else
            $desktop = 0
        EndIf
    EndIf

    ;Where is the active window
    $activeWindowPosition = WinGetPos("[ACTIVE]")
    If $smPosition = "Left" Then
        If $activeWindowPosition[0] < 0 Then ;If Active Window is in monitor on left
            If $desktop = 0 Then
                $decided = 1
                $returnValue = "Hide"
            Else
                $returnValue = "Show"
            EndIf
        EndIf
    Else ;$smPosition = "Right"
        If $activeWindowPosition[0] > (@DesktopWidth - 1) Or _ ;If Active Window is in monitor on right
                $activeWindowPosition[0] = (@DesktopWidth - 8) Then ;If Active Window is fullscreen
            If $desktop = 0 Then
                $decided = 1
                $returnValue = "Hide"
            Else
                $returnValue = "Show"
            EndIf
        EndIf
    EndIf

    ;Only check if undecided
    If $decided = 0 Then
        ;Where is the mouse located
        If $smPosition = "Left" Then
            If MouseGetPos(0) < 0 Then ;If mouse is in monitor on left
                $decided = 1
                $returnValue = "Hide"
            EndIf
        Else ;$smPosition = "Right"
            If MouseGetPos(0) > @DesktopWidth Then ;If mouse is in monitor on right
                $decided = 1
                $returnValue = "Hide"
            EndIf
        EndIf
        If $decided = 0 Then
            ;Is there a special Window that is active?
            $mPos = _WinAPI_GetMousePos()
            $hwnd = _WinAPI_WindowFromPoint($mPos)
            ;If $hwnd = $inputDirector Then
            ;Is VNC active?
            If WinGetTitle($hwnd) = "Cursor Hider" Then
                $decided = 1
                ;Temporary while VNC is in main window
                ;$returnValue = "Hide"
                $returnValue = "Show"
            EndIf
        EndIf
    EndIf

    ;Is the Toggle set to hide?
    ;Is Screensaver Off?
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "ForceFSSOn") = 0 Then
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") = "Hide" Then
            ;Replace Black with image, in anticipation of screen turning back on
            _GDIPlus_BitmapDispose($pic)
            $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image
            GUICtrlSetPos($pic, $smCenterX, $smCenterY)
            GUISetBkColor(0)
            ;Hide GUI
            $decided = 1
            $returnValue = "Hide"
        EndIf
    Else
        $returnValue = "Show" ;Screensaver is active
    EndIf

    ;If no issues, then show
    If $decided = 0 Then
        $returnValue = "Show"
    EndIf
    Return $returnValue
EndFunc   ;==>CheckIfFSSshouldDisplay
Func CheckForImageChanges()
    Local $newCount = _FileListToArray($pictureFolder)
    If $newCount[0] <> $imageCount Then
        $imageList = _FileListToArray($pictureFolder)
        $imageCount = $imageList[0]
        ReDim $imageShown[$imageCount + 1]
    EndIf
EndFunc   ;==>CheckForImageChanges
Func GetSettings()
    Global $settingsFile = FileOpen(@WorkingDir & "\FSS.txt", 0)
    Local $lineNumber = 1
    Local $line = FileReadLine($settingsFile, $lineNumber)
    Local $lineSplit, $description, $value

    ;Move to the Fullscreen Slideshow Section
    While $line <> "Fullscreen Slideshow"
        $line = FileReadLine($settingsFile, $lineNumber)
        $lineNumber += 1
        Sleep(10)
    WEnd
    $lineNumber += 2 ;Move past the divider line

    ;Read until the next section
    While $line <> ";===================================="
        $line = FileReadLine($settingsFile, $lineNumber)
        If $line = ";====================================" Then
            ExitLoop
        EndIf
        ;Split line by Description and value
        $lineSplit = StringSplit($line, " = ", 1)
        $description = $lineSplit[1]
        $value = $lineSplit[2]
        If $description = "Picture Folder" Then
            Global $pictureFolder = $value
        ElseIf $description = "Show Tray Icon" Then
            Global $showIcon = $value
        ElseIf $description = "Secondary Monitor Width" Then
            Global $smWidth = $value
        ElseIf $description = "Secondary Monitor Height" Then
            Global $smHeight = $value
        ElseIf $description = "Monitor Position (Left, Right)" Then
            Global $smPosition = $value
        ElseIf $description = "Activation Mode (Inactive, Timer)" Then
            Global $activationMode = $value
        ElseIf $description = "Timer Seconds" Then
            Global $ssTimerSeconds = $value
        ElseIf $description = "Change Method (Timer, Refresh)" Then
            Global $changeMode = $value
        ElseIf $description = "Image Change Time (In Seconds)" Then
            Global $timerSeconds = $value
        ElseIf $description = "Image Order (Ordered, Random, Random No Repeat)" Then
            Global $randomImages = $value
        ElseIf $description = "Taskbar Size (Default: 40)" Then
            Global $taskbarSize = $value
        ElseIf $description = "Run Screensaver (Yes, No)" Then
            Global $runScreensaver = $value
        ElseIf $description = "Close with Screensaver (Yes, No)" Then
            Global $closeWithScreensaver = $value
        ElseIf $description = "Start with Windows (Yes, No)" Then
            Global $startWithWindows = $value
        EndIf
        $lineNumber += 1
        Sleep(10)
    WEnd
    FileClose($settingsFile)
EndFunc   ;==>GetSettings
Func GetMonitorInformation()
    Local $mouseX, $mouseX2, $mouseY, $mouseY2, $monitorPosition, $smResolutionX, $smResolutionY
    BlockInput(1)
    MsgBox(0, "Calibrating", "Calibrating Monitors, please wait...", 3)
    MouseMove(0, 0, 0)
    Sleep(200)
    $mouseX = MouseGetPos(0)
    $mouseY = MouseGetPos(1)

    ;Get X Resolution
    MouseMove(MouseGetPos(0) - 1, 0, 5) ;Move mouse 1 pixel left
    $mouseX2 = MouseGetPos(0) ;Save new position to mx2
    While $mouseX <> $mouseX2 ;If position is different
        $mouseX = MouseGetPos(0) ;save position to mx1
        MouseMove(MouseGetPos(0) - 1, 0, 5) ;move mouse to left
        $mouseX2 = MouseGetPos(0) ;save position to mx2
        Sleep(10)
    WEnd ;compare again
    If (MouseGetPos(0)) < 0 Then
        $monitorPosition = "Left"
        ;Get Y Resolution
    EndIf
    MsgBox(0, "Complete", "Monitors have been calibrated, thank you.", 3)
    BlockInput(0)
EndFunc   ;==>GetMonitorInformation

Slideshow before GDI modifications

#include <File.au3>
#include <GetFileProperty.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Timers.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>

;Only allow one instance of the program to run.
If _Singleton("Fullscreen Slideshow", 1) = 0 Then
    Exit
EndIf

;Settings
;====================================
GetSettings()
;====================================
Global $desktop
Global $ssTimerSet = 0
Global $countedImages = 0
Global $imageWasShown = 1
Global $hidden = 0
Global $VNChidden = 0
Global $checkCount = 1
Global $taskbarActivationHide = 0
;Global $inputDirector = WinGetHandle("Cursor Hider")
;Uknown glitch fix
;$inputDirector = 0x00530C46
;======
Global $imageList = _FileListToArray($pictureFolder)
Global $imageCount = $imageList[0]
Global $imageShown[$imageCount + 1]
Global $resetCount = 0
Global $reset = 0
Global Const $STM_SETIMAGE = 0x0172
Global $currActiveWindow = WinGetHandle("")
Global $imageChangedBlack = 0
Global $imageWidth, $imageHeight, $pHeight, $pWidth, $smCenterX, $smCenterY, _
        $picName, $activeWindowPosition, $refreshImage, $imageTimer, $screenSaverTimer, _
        $startWithWindows, $closeWithScreensaver
Global $screenSaverOpened = 0
Global $winSize[2]

;GetMonitorInformation()
GetImage()

;GUI
;Hidden GUI for fixing if FSS becomes the active window
GUICreate("FSS", 0, 0, 0, 0)

;Parent, for taskbar hide effect
$GUIHide = GUICreate("hide", 0, 0, 0, 0)

;Actual GUI to be used
$GUI = GUICreate("Fullscreen Slideshow", $smWidth, $smHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the screen
$pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image
GUICtrlSetPos($pic, $smCenterX, $smCenterY)
GUISetBkColor(0)
GUISetState()
MoveWindow()
$imageTimer = TimerInit() ;Reset Image Change Timer
WinActivate(HWnd($currActiveWindow)) ;Activate window that was previously active

;Fix for sudden power failure (screensaver fix)
RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "ForceFSSOn", "REG_SZ", 0)

;Main Program
While 1
    ;Debug
;~  ToolTip(CheckIfFSSshouldDisplay() & @CRLF & _
;~          "Active: " & $activeWindowPosition[0] & ", " & $activeWindowPosition[1] & @CRLF & _
;~          "Mouse: " & MouseGetPos(0) & ", " & MouseGetPos(1) & @CRLF & _
;~          "Desktop: " & $desktop & @CRLF & _
;~          "Monitor: " & @DesktopWidth & "x" & @DesktopHeight _
;~          , 100, 5)
    ;==========================

    ;Show Tray Icon?
    If $showIcon = "No" Then
        AutoItSetOption("TrayIconHide", 1)
    Else
        AutoItSetOption("TrayIconHide", 0)
    EndIf

    ;Start with Windows?
    If $startWithWindows = "Yes" Then
        If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow") = "" Then
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow", "REG_SZ", '"' & @ScriptFullPath & '"')
        EndIf
    Else
        If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow") <> "" Then
            RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow")
        EndIf
    EndIf

    ;Close program if Screensaver closes
    If $closeWithScreensaver = "Yes" Then
        If $screenSaverOpened = 1 Then
            If ProcessExists("Fullscreen Screensaver.exe") = 0 Then
                Exit
            EndIf
        EndIf
    EndIf

    ;Make sure Fullscreen Screensaver is running
    If $runScreensaver = "Yes" Then
        If ProcessExists("Fullscreen Screensaver.exe") = 0 Then
            Run("D:\Autoit Scripts\Fullscreen Screensaver.exe")
            $screenSaverOpened = 1
        Else
            $screenSaverOpened = 1
        EndIf
    EndIf

    ;Always keep FSS on top of other windows
    WinSetOnTop("Fullscreen Slideshow", "", 0)
    WinSetOnTop("Fullscreen Slideshow", "", 1)

    ;If Fullscreen Slideshow becomes the active window, change to FSS
    If WinActive("Fullscreen Slideshow", "") <> 0 Then
        WinActivate("FSS", "")
    EndIf

    ;Should Fullscreen Slideshow be on or off
    If CheckIfFSSshouldDisplay() = "Show" Then
        If $activationMode = "Inactive" Then ;Monitor not in use
            WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
        Else ;$activationMode = "Timer" (Screensaver mode)
            If TimerDiff($screenSaverTimer) > ($ssTimerSeconds * 1000) Then
                WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
            EndIf
        EndIf
    Else
        ;Skype Black Screen Glitch
        ;============
        If WinExists("[CLASS:tchatcontentcontrol]") = 1 Then
            WinClose("[CLASS:tchatcontentcontrol]")
        EndIf
        ;============
        WinSetState("Fullscreen Slideshow", "", @SW_HIDE)
        $refreshImage = 1
        $screenSaverTimer = TimerInit() ;Reset Screensaver Timer
    EndIf

    ;Changing the Image
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") <> "Monitor Off" Then
        $imageChangedBlack = 0
        If $changeMode = "Refresh" Then
            If $refreshImage = 1 Then
                $refreshImage = 0
                GetImage()
                GUICtrlDelete($pic)
                $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image
                GUICtrlSetPos($pic, $smCenterX, $smCenterY)
                GUISetBkColor(0)
            EndIf
        Else ;$changeMode = "Timer"
            If TimerDiff($imageTimer) > ($timerSeconds * 1000) Then
                GetImage()
                GUICtrlDelete($pic)
                $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image
                GUICtrlSetPos($pic, $smCenterX, $smCenterY)
                GUISetBkColor(0)
                $imageTimer = TimerInit() ;Reset Image Change Timer
            EndIf
        EndIf
    Else ;Use Black Image
        If $imageChangedBlack = 0 Then
            $imageChangedBlack = 1
            GUICtrlDelete($pic)
            $pic = GUICtrlCreatePic("D:\All Black.jpg", 0, 0, $smWidth, $smHeight)
        EndIf
    EndIf

    ;Hide/Show Taskbar
    If MouseGetPos(0) > 0 And MouseGetPos(0) < @DesktopWidth Then ;If mouse is in main monitor
        If MouseGetPos(1) > (@DesktopHeight - 2) Then ;If mouse is at bottom of screen
            ShowTaskBar()
        ElseIf MouseGetPos(1) < (@DesktopHeight - $taskbarSize) Then ;If mouse leaves taskbar area
            If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Blink Taskbar") = 0 Then HideTaskBar()
        EndIf
    Else
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Blink Taskbar") = 0 Then HideTaskBar()
    EndIf

    ;Only every 5 times
    If $checkCount > 5 Then
        $checkCount = 1
        ;Pre-cautionary in case of changes in Monitor dimensions (if secondary monitor is unplugged)
        MoveWindow()
        ;Check settings for changes
        GetSettings()
    Else
        $checkCount += 1
    EndIf

    ;Allow CPU to rest
    Sleep(100)
WEnd
Func GetImage()
    Local $newPic = 0

    ;Change count, if image folder changes
    CheckForImageChanges()

    If $randomImages = "Ordered" Then
        ;Counted Images default is 0
        $countedImages += 1
        ;If the the counted images surpasses the number of images that are there, then reset the count
        If $countedImages > $imageCount Then
            $countedImages = 1
        EndIf
        $picName = $countedImages
    ElseIf $randomImages = "Random" Then
        ;Select a random image from the list
        $picName = Random(1, $imageCount, 1)
    Else ;$randomImages = "Random No Repeat"

        If $reset = 1 Then
            $reset = 0
            $resetCount = 0
            For $x = 1 To $imageCount Step +1
                $imageShown[$x] = ""
            Next
        EndIf
        While $newPic <> 1
            $picName = Random(1, $imageCount, 1) ;Pick a random image
            ;Check if image has been shown
            For $y = 1 To $imageCount Step +1
                If $picName = $imageShown[$y] Then
                    $imageWasShown = 1
                EndIf
            Next ;y
            If $imageWasShown = 1 Then
                $imageWasShown = 0
                $newPic = 0
            Else
                $newPic = 1
                $resetCount += 1
            EndIf
            If $resetCount = $imageCount Then
                $reset = 1
            EndIf
        WEnd
        ;Save image to shown image list
        ;Store name in next available empty slot
        For $x = 1 To $imageCount Step +1
            If $imageShown[$x] = "" Then
                $imageShown[$x] = $picName ;Save image to shown image list
                ExitLoop ;End loop early
            EndIf
        Next
    EndIf

    ;Get Dimensions of image
    GetDimensions($imageList[$picName])
    $imageHeight = $pHeight
    $imageWidth = $pWidth

    ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $imageWidth > $smWidth Or $imageHeight > $smHeight Then
        ;Get aspect ratio
        $aspectRatioX = $smWidth / $imageWidth ;Aspect ratio = 1280 / image X
        $aspectRatioY = $smHeight / $imageHeight ;Aspect ratio = 800 / image Y
        If $aspectRatioX < $aspectRatioY Then
            ;Image is wide
            ;New Height
            $imageHeight = $smWidth * ($imageHeight / $imageWidth)
            $imageWidth = $smWidth
        Else
            ;Image is tall
            ;New Width
            $imageWidth = $smHeight * ($imageWidth / $imageHeight)
            $imageHeight = $smHeight
        EndIf
        $imageWidth = Int($imageWidth) ;Convert iW into integer
        $imageHeight = Int($imageHeight) ;Convert iH into integer
    EndIf

    ;Calculate Center
    ;(Monitor size - image size) / 2
    $smCenterX = ($smWidth - $imageWidth) / 2
    $smCenterY = ($smHeight - $imageHeight) / 2
EndFunc   ;==>GetImage

Func GetDimensions($picName)
    Local $prop, $dArray
    $path = $pictureFolder & "\" & $picName
    $prop = _GetFileProperty($path, "Dimensions")
    $dArray = StringSplit($prop, " x ")
    $pWidth = Number(StringMid($dArray[1], 2))
    $pHeight = Number($dArray[4])
EndFunc   ;==>GetDimensions
Func MoveWindow()
    Local $position = WinGetPos("Fullscreen Slideshow")
    If $smPosition = "Left" Then
        If $position[0] <> (-1 * $smWidth) Or $position[1] <> $smHeight Then
            WinMove("Fullscreen Slideshow", "", (-1 * $smWidth), 0, $smWidth, $smHeight)
        EndIf
    Else
        If $position[0] <> @DesktopWidth Or $position[1] <> $smHeight Then
            WinMove("Fullscreen Slideshow", "", @DesktopWidth, 0, $smWidth, $smHeight)
        EndIf
    EndIf
EndFunc   ;==>MoveWindow
Func HideTaskBar()
    ControlHide('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
    ControlHide('', '', WinGetHandle("[CLASS:Button]"))
EndFunc   ;==>HideTaskBar
Func ShowTaskBar()
    ControlShow('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
    ControlShow('', '', WinGetHandle("[CLASS:Button]"))
EndFunc   ;==>ShowTaskBar

Func CheckIfFSSshouldDisplay()
    Local $decided = 0
    Local $returnValue

    ;Is selected window the Desktop?
    $winSize = WinGetClientSize("")
    If $winSize = "" Then ;Prevents non-accessible glitch
        $desktop = 0
    Else
        If $winSize[0] = @DesktopWidth + $smWidth Then ;Desktop
            $desktop = 1
        Else
            $desktop = 0
        EndIf
    EndIf

    ;Where is the active window
    $activeWindowPosition = WinGetPos("[ACTIVE]")
    If $smPosition = "Left" Then
        If $activeWindowPosition[0] < 0 Then ;If Active Window is in monitor on left
            If $desktop = 0 Then
                $decided = 1
                $returnValue = "Hide"
            Else
                $returnValue = "Show"
            EndIf
        EndIf
    Else ;$smPosition = "Right"
        If $activeWindowPosition[0] > (@DesktopWidth - 1) Or _ ;If Active Window is in monitor on right
                $activeWindowPosition[0] = (@DesktopWidth - 8) Then ;If Active Window is fullscreen
            If $desktop = 0 Then
                $decided = 1
                $returnValue = "Hide"
            Else
                $returnValue = "Show"
            EndIf
        EndIf
    EndIf

    ;Only check if undecided
    If $decided = 0 Then
        ;Where is the mouse located
        If $smPosition = "Left" Then
            If MouseGetPos(0) < 0 Then ;If mouse is in monitor on left
                $decided = 1
                $returnValue = "Hide"
            EndIf
        Else ;$smPosition = "Right"
            If MouseGetPos(0) > @DesktopWidth Then ;If mouse is in monitor on right
                $decided = 1
                $returnValue = "Hide"
            EndIf
        EndIf
        If $decided = 0 Then
            ;Is there a special Window that is active?
            $mPos = _WinAPI_GetMousePos()
            $hwnd = _WinAPI_WindowFromPoint($mPos)
            ;If $hwnd = $inputDirector Then
            ;Is VNC active?
            If WinGetTitle($hwnd) = "Cursor Hider" Then
                $decided = 1
                ;Temporary while VNC is in main window
                ;$returnValue = "Hide"
                $returnValue = "Show"
            EndIf
        EndIf
    EndIf

    ;Is the Toggle set to hide?
    ;Is Screensaver Off?
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "ForceFSSOn") = 0 Then
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") = "Hide" Then
            ;Replace Black with image, in anticipation of screen turning back on
            GUICtrlDelete($pic)
            $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image
            GUICtrlSetPos($pic, $smCenterX, $smCenterY)
            GUISetBkColor(0)
            ;Hide GUI
            $decided = 1
            $returnValue = "Hide"
        EndIf
    Else
        $returnValue = "Show" ;Screensaver is active
    EndIf

    ;If no issues, then show
    If $decided = 0 Then
        $returnValue = "Show"
    EndIf
    Return $returnValue
EndFunc   ;==>CheckIfFSSshouldDisplay
Func CheckForImageChanges()
    Local $newCount = _FileListToArray($pictureFolder)
    If $newCount[0] <> $imageCount Then
        $imageList = _FileListToArray($pictureFolder)
        $imageCount = $imageList[0]
        ReDim $imageShown[$imageCount + 1]
    EndIf
EndFunc   ;==>CheckForImageChanges
Func GetSettings()
    Global $settingsFile = FileOpen(@WorkingDir & "\FSS.txt", 0)
    Local $lineNumber = 1
    Local $line = FileReadLine($settingsFile, $lineNumber)
    Local $lineSplit, $description, $value

    ;Move to the Fullscreen Slideshow Section
    While $line <> "Fullscreen Slideshow"
        $line = FileReadLine($settingsFile, $lineNumber)
        $lineNumber += 1
        Sleep(10)
    WEnd
    $lineNumber += 2 ;Move past the divider line

    ;Read until the next section
    While $line <> ";===================================="
        $line = FileReadLine($settingsFile, $lineNumber)
        If $line = ";====================================" Then
            ExitLoop
        EndIf
        ;Split line by Description and value
        $lineSplit = StringSplit($line, " = ", 1)
        $description = $lineSplit[1]
        $value = $lineSplit[2]
        If $description = "Picture Folder" Then
            Global $pictureFolder = $value
        ElseIf $description = "Show Tray Icon" Then
            Global $showIcon = $value
        ElseIf $description = "Secondary Monitor Width" Then
            Global $smWidth = $value
        ElseIf $description = "Secondary Monitor Height" Then
            Global $smHeight = $value
        ElseIf $description = "Monitor Position (Left, Right)" Then
            Global $smPosition = $value
        ElseIf $description = "Activation Mode (Inactive, Timer)" Then
            Global $activationMode = $value
        ElseIf $description = "Timer Seconds" Then
            Global $ssTimerSeconds = $value
        ElseIf $description = "Change Method (Timer, Refresh)" Then
            Global $changeMode = $value
        ElseIf $description = "Image Change Time (In Seconds)" Then
            Global $timerSeconds = $value
        ElseIf $description = "Image Order (Ordered, Random, Random No Repeat)" Then
            Global $randomImages = $value
        ElseIf $description = "Taskbar Size (Default: 40)" Then
            Global $taskbarSize = $value
        ElseIf $description = "Run Screensaver (Yes, No)" Then
            Global $runScreensaver = $value
        ElseIf $description = "Close with Screensaver (Yes, No)" Then
            Global $closeWithScreensaver = $value
        ElseIf $description = "Start with Windows (Yes, No)" Then
            Global $startWithWindows = $value
        EndIf
        $lineNumber += 1
        Sleep(10)
    WEnd
    FileClose($settingsFile)
EndFunc   ;==>GetSettings
Func GetMonitorInformation()
    Local $mouseX, $mouseX2, $mouseY, $mouseY2, $monitorPosition, $smResolutionX, $smResolutionY
    BlockInput(1)
    MsgBox(0, "Calibrating", "Calibrating Monitors, please wait...", 3)
    MouseMove(0, 0, 0)
    Sleep(200)
    $mouseX = MouseGetPos(0)
    $mouseY = MouseGetPos(1)

    ;Get X Resolution
    MouseMove(MouseGetPos(0) - 1, 0, 5) ;Move mouse 1 pixel left
    $mouseX2 = MouseGetPos(0) ;Save new position to mx2
    While $mouseX <> $mouseX2 ;If position is different
        $mouseX = MouseGetPos(0) ;save position to mx1
        MouseMove(MouseGetPos(0) - 1, 0, 5) ;move mouse to left
        $mouseX2 = MouseGetPos(0) ;save position to mx2
        Sleep(10)
    WEnd ;compare again
    If (MouseGetPos(0)) < 0 Then
        $monitorPosition = "Left"
        ;Get Y Resolution
    EndIf
    MsgBox(0, "Complete", "Monitors have been calibrated, thank you.", 3)
    BlockInput(0)
EndFunc   ;==>GetMonitorInformation

FSS.txt

Fullscreen Slideshow
;====================================
Picture Folder = D:\Wallpapers
Show Tray Icon = No
Secondary Monitor Width = 1280
Secondary Monitor Height = 800
Monitor Position (Left, Right) = Right
Activation Mode (Inactive, Timer) = Inactive
Timer Seconds = 5
Change Method (Timer, Refresh) = Timer
Image Change Time (In Seconds) = 60
Image Order (Ordered, Random, Random No Repeat) = Random No Repeat
Taskbar Size (Default: 40) = 40
Run Screensaver (Yes, No) = No
Close with Screensaver (Yes, No) = Yes
Start with Windows (Yes, No) = No
;====================================

Fullscreen Screensaver
;====================================
Picture Folder = D:\Wallpapers
Show Tray Icon = No
Primary Monitor Screensaver = On
Activation Time (In Seconds) = 300
Image Change Time (In Seconds) = 30
Run Slideshow (Yes, No) = Yes
Close with Slideshow (Yes, No) = Yes
Start with Windows (Yes, No) = No
Rows (Horizontal Cuts) = 3
Columns (Vertical Cuts) = 6
Percent = 50
Check Times = 3
;====================================

Fullscreen Slideshow - GDIPlus.au3

Fullscreen Slideshow.au3

FSS.txt

GetFileProperty.au3

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

  • Solution

I'm not surprised your head hurts, as that is quite a significant amount of code to wade through.

By my quick look, it is not just lines 81 to 84 that could be at issue here, as some other elements in your While..Wend act on the Timer, including a reset. However it was doing my head in trying to follow the logic.

I would recommend you simplify it for testing, and then add elements back in.

I see you are doing repeated calls to TimerDiff, when at least in one instance (didn't check them all), you should just do it once and store in a variable (Lines 81 & 82).

Seems to be an awful lot going on, and I'm not about to torture myself trying to gain an understanding.

I would be using variables and checking on their values with a MsgBox or even writing to an INI file instead, if need be.

My quick perusal didn't show me the significance of the FSS.txt file? Are you reading that for values? If so, then an INI read & write and format might be better as a settings file.

Those are my observations, as is the fact, that the best person to troubleshoot code, is usually the person who wrote it.

Possibly you need to rewrite some of it, clarifying your understanding as you go, and using comments.

One way to simplify things, is to turn unrelated stuff into functions. That gives you less to wade through, and makes it easier to focus where you should.

You certainly need to process it step by step.

There is no substitute for doing the hard yards when it comes to code ... someone has to do it.

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Link to comment
Share on other sites

I think you're right. In the past, I have recoded everything before to make it easier.

It becomes sloppy when you add new things that you didn't previously account for.

It will certainly take a bit of time to recode this demon, so I will return to let you know the results upon completion.

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

Actually, you're correct JohnOne. After tearing everything apart and reassembling it, I think I was looking at the wrong variables.

This one is so far functioning without glitches. I'm sure the GDI handling is sloppy, I'm new to GDI.

Still using a text file for the settings, since I'm not in the mood to recode write lines into ini.

Thank you everyone for your help.

#include <File.au3>
#include <GetFileProperty.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Timers.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <GDIPlus.au3>
_GDIPlus_Startup()

;Only allow one instance of the program to run.
If _Singleton("Fullscreen Slideshow", 1) = 0 Then
    Exit
EndIf

Global $pictureFolder ;Fixes declared warning
;Settings
;====================================
;Can be edited via external text file (FSS.txt)
GetSettings()
;====================================

Global $desktop
Global $ssTimerSet = 0
Global $countedImages = 0
Global $imageWasShown = 1
Global $hidden = 0
Global $VNChidden = 0
Global $checkCount = 1
Global $taskbarActivationHide = 0
Global $imageList = _FileListToArray($pictureFolder)
Global $imageCount = $imageList[0]
Global $imageShown[$imageCount + 1]
Global $resetCount = 0
Global $reset = 0
Global $changeImage = 0
Global Const $STM_SETIMAGE = 0x0172
Global $currActiveWindow = WinGetHandle("")
Global $imageChangedBlack = 0
Global $imageWidth, $imageHeight, $pHeight, $pWidth, $smCenterX, $smCenterY, _
        $picName, $activeWindowPosition, $refreshImage, $imageTimer, $screenSaverTimer, _
        $startWithWindows, $closeWithScreensaver, $pic, $gdiPic, $position
Global $screenSaverOpened = 0
Global $winSize[2]

;Preliminary setup - Creates GUI, displays 1 image
;====================================
GetImageForDisplay()
CreateGUI()
GUISetState(@SW_SHOW)
MoveGUIWindow()
;$imageTimer = TimerInit() ;Reset Image Change Timer
ShowImage()

;Main Program
;====================================
While 1
    ;Debug
;~  ToolTip(CheckIfFSSshouldDisplay() & @CRLF & _
;~          "Active: " & $activeWindowPosition[0] & ", " & $activeWindowPosition[1] & @CRLF & _
;~          "Mouse: " & MouseGetPos(0) & ", " & MouseGetPos(1) & @CRLF & _
;~          "Desktop: " & $desktop & @CRLF & _
;~          "Monitor: " & @DesktopWidth & "x" & @DesktopHeight _
;~          , 100, 5)
    ;==========================


    ;These functions are set in settings (FSS.txt)
    ShowTrayIcon() ;Should Tray Icon be shown?
    StartWithWindows() ;Start program with Windows? (doesn't function)
    CloseWithScreensaver() ;Close slideshow along with screensaver?
    RunScreensaver() ;Run Screensaver along with slideshow?
    ;================
    AlwaysOnTop() ;Force slideshow to be on top of other windows
    LoseFocus() ;Lose focus in case slideshow becomes the active window

    ;Should Fullscreen Slideshow be on or off
    If CheckIfFSSshouldDisplay() = "Show" Then
        ShowFSS()
    Else
        HideFSS()
    EndIf
    ChangeImage()
    DisplayTaskbar()

    ;Only every 5 times
    ConsoleWrite("Check Count: " & $checkCount & @CRLF)
    If $checkCount > 5 Then
        $checkCount = 1
        ;Pre-cautionary in case of changes in Monitor dimensions (if secondary monitor is unplugged)
        MoveGUIWindow()
        ;Check settings for changes
        GetSettings()
    Else
        $checkCount += 1
    EndIf

    ConsoleWrite(@CRLF & "=======================================================================" & @CRLF)
    ;Allow CPU to rest
    Sleep(10)
WEnd

_GDIPlus_Shutdown()



;Beginning of Functions
;====================================

Func GetSettings()
    ConsoleWrite("=Get Settings=" & @CRLF)
    Global $settingsFile = FileOpen(@WorkingDir & "\FSS.txt", 0)
    Local $lineNumber = 1
    Local $line = FileReadLine($settingsFile, $lineNumber)
    Local $lineSplit, $description, $value

    ;Move to the Fullscreen Slideshow Section
    While $line <> "Fullscreen Slideshow"
        $line = FileReadLine($settingsFile, $lineNumber)
        $lineNumber += 1
        Sleep(10)
    WEnd
    $lineNumber += 2 ;Move past the divider line

    ;Read until the next section
    While $line <> ";===================================="
        $line = FileReadLine($settingsFile, $lineNumber)
        If $line = ";====================================" Then
            ExitLoop
        EndIf
        ;Split line by Description and value
        $lineSplit = StringSplit($line, " = ", 1)
        $description = $lineSplit[1]
        $value = $lineSplit[2]
        If $description = "Picture Folder" Then
            ConsoleWrite("Picture Folder: " & $value & @CRLF)
            $pictureFolder = $value
        ElseIf $description = "Show Tray Icon" Then
            ConsoleWrite("Show Tray Icon: " & $value & @CRLF)
            Global $showIcon = $value
        ElseIf $description = "Secondary Monitor Width" Then
            ConsoleWrite("SM Width: " & $value & @CRLF)
            Global $smWidth = $value
        ElseIf $description = "Secondary Monitor Height" Then
            ConsoleWrite("SM Height: " & $value & @CRLF)
            Global $smHeight = $value
        ElseIf $description = "Monitor Position (Left, Right)" Then
            ConsoleWrite("MP: " & $value & @CRLF)
            Global $smPosition = $value
        ElseIf $description = "Activation Mode (Inactive, Timer)" Then
            ConsoleWrite("Activation Mode: " & $value & @CRLF)
            Global $activationMode = $value
        ElseIf $description = "Screensaver Timer Seconds" Then
            ConsoleWrite("SS Timer: " & $value & @CRLF)
            Global $ssTimerSeconds = $value
            $ssTimerSeconds = $ssTimerSeconds * 1000 ;Convert to milliseconds
        ElseIf $description = "Change Method (Timer, Refresh)" Then
            ConsoleWrite("Change Method: " & $value & @CRLF)
            Global $changeMode = $value
        ElseIf $description = "Image Change Time (In Seconds)" Then
            ConsoleWrite("Image Change Time: " & $value & @CRLF)
            Global $timerSeconds = $value
            $timerSeconds = $timerSeconds * 1000 ;Convert to milliseconds
        ElseIf $description = "Image Order (Ordered, Random, Random No Repeat)" Then
            ConsoleWrite("Image Order: " & $value & @CRLF)
            Global $randomImages = $value
        ElseIf $description = "Taskbar Size (Default: 40)" Then
            ConsoleWrite("Taskbar Size: " & $value & @CRLF)
            Global $taskbarSize = $value
        ElseIf $description = "Run Screensaver (Yes, No)" Then
            ConsoleWrite("Run Screensaver: " & $value & @CRLF)
            Global $runScreensaver = $value
        ElseIf $description = "Close with Screensaver (Yes, No)" Then
            ConsoleWrite("Close with Screensaver: " & $value & @CRLF)
            Global $closeWithScreensaver = $value
        ElseIf $description = "Start with Windows (Yes, No)" Then
            ConsoleWrite("Start with Windows: " & $value & @CRLF)
            Global $startWithWindows = $value
        EndIf
        $lineNumber += 1
        Sleep(10)
    WEnd
    FileClose($settingsFile)
EndFunc   ;==>GetSettings

Func GetImageForDisplay()
    ConsoleWrite("=GetImageForDisplay=" & @CRLF)
    Local $newPic = 0
    Local $hHBmp ;for GDI

    ;Check image folder for count change
    CheckForImageChanges()

    ;Images should go in order by file
    If $randomImages = "Ordered" Then
        ;Counted Images default is 0
        $countedImages += 1
        ;If the the counted images surpasses the number of images that are there, then reset the count
        If $countedImages > $imageCount Then
            $countedImages = 1
        EndIf
        $picName = $countedImages
        ;Select a random image from the list
    ElseIf $randomImages = "Random" Then
        ;Select a random image from the list
        $picName = Random(1, $imageCount, 1)
        ;Select a random image, but do not show the same image twice
    Else ;$randomImages = "Random No Repeat"
        If $reset = 1 Then
            $reset = 0
            $resetCount = 0
            For $x = 1 To $imageCount Step +1
                $imageShown[$x] = ""
            Next
        EndIf
        While $newPic <> 1
            $picName = Random(1, $imageCount, 1) ;Pick a random image
            ;Check if image has been shown
            For $y = 1 To $imageCount Step +1
                If $picName = $imageShown[$y] Then
                    $imageWasShown = 1
                EndIf
            Next ;y
            If $imageWasShown = 1 Then
                $imageWasShown = 0
                $newPic = 0
            Else
                $newPic = 1
                $resetCount += 1
            EndIf
            If $resetCount = $imageCount Then
                $reset = 1
            EndIf
        WEnd
        ;Save image to shown image list
        ;Store name in next available empty slot
        For $x = 1 To $imageCount Step +1
            If $imageShown[$x] = "" Then
                $imageShown[$x] = $picName ;Save image to shown image list
                ExitLoop ;End loop early
            EndIf
        Next
    EndIf

    ;Get Dimensions of image
    GetDimensions($imageList[$picName])
    $imageHeight = $pHeight
    $imageWidth = $pWidth

    ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $imageWidth > $smWidth Or $imageHeight > $smHeight Then
        ;Get aspect ratio
        $aspectRatioX = $smWidth / $imageWidth ;Aspect ratio = monitor horizontal / image X
        $aspectRatioY = $smHeight / $imageHeight ;Aspect ratio = monitor vertical / image Y
        If $aspectRatioX < $aspectRatioY Then
            ;Image is wide
            ;New Height
            $imageHeight = $smWidth * ($imageHeight / $imageWidth)
            $imageWidth = $smWidth
        Else
            ;Image is tall
            ;New Width
            $imageWidth = $smHeight * ($imageWidth / $imageHeight)
            $imageHeight = $smHeight
        EndIf
        $imageWidth = Int($imageWidth) ;Convert imageWidth into integer
        $imageHeight = Int($imageHeight) ;Convert imageHeight into integer
    EndIf

    ;Calculate Center of monitor
    ;(Monitor size - image size) / 2
    $smCenterX = ($smWidth - $imageWidth) / 2
    $smCenterY = ($smHeight - $imageHeight) / 2

    ;Resize the image
    $hHBmp = $pictureFolder & "\" & $imageList[$picName]
    $gdiPic = _GDIPlus_BitmapCreateFromFile($hHBmp) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
    $pic = _GDIPlus_ImageResize($gdiPic, $imageWidth, $imageHeight) ;resize image
EndFunc   ;==>GetImageForDisplay

Func GetDimensions($picName)
    ConsoleWrite("=GetDimensions=" & @CRLF)
    Local $prop, $dArray
    $path = $pictureFolder & "\" & $picName
    $prop = _GetFileProperty($path, "Dimensions")
    $dArray = StringSplit($prop, " x ")
    $pWidth = Number(StringMid($dArray[1], 2))
    $pHeight = Number($dArray[4])
EndFunc   ;==>GetDimensions

Func CheckForImageChanges()
    ConsoleWrite("=CheckForImageChanges=" & @CRLF)
    Local $newCount = _FileListToArray($pictureFolder)
    If $newCount[0] <> $imageCount Then
        $imageList = _FileListToArray($pictureFolder)
        $imageCount = $imageList[0]
        ReDim $imageShown[$imageCount + 1]
    EndIf
EndFunc   ;==>CheckForImageChanges

Func CreateGUI()
    ConsoleWrite("=CreateGUI=" & @CRLF)
    ;Hidden GUI for fixing if FSS becomes the active window
    GUICreate("FSS", 0, 0, 0, 0)
    ;Parent, for window border hide effect
    $GUIHide = GUICreate("hide", 0, 0, 0, 0)
    ;Actual GUI to be used
    Global $GUI = GUICreate("Fullscreen Slideshow", $smWidth, $smHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the screen
    GUICtrlSetPos($pic, $smCenterX, $smCenterY)
    GUISetBkColor(0)
EndFunc   ;==>CreateGUI

Func MoveGUIWindow()
    ConsoleWrite("=MoveGUIWindow=" & @CRLF)
    ;Move GUI according to location of secondary monitor
    ;$position = WinGetPos("Fullscreen Slideshow")
    If $smPosition = "Left" Then
        ;If $position[0] <> (-1 * $smWidth) Or $position[1] <> $smHeight Then
        WinMove("Fullscreen Slideshow", "", (-1 * $smWidth), 0, $smWidth, $smHeight)
        ;EndIf
    Else ;Monitor on Right
        ;If $position[0] <> @DesktopWidth Or $position[1] <> $smHeight Then
        WinMove("Fullscreen Slideshow", "", @DesktopWidth, 0, $smWidth, $smHeight)
        ;EndIf
    EndIf
EndFunc   ;==>MoveGUIWindow

Func ShowImage()
    ConsoleWrite("=ShowImage=" & @CRLF)
    If $imageChangedBlack = 0 Then
        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI) ;create a graphics object from a window handle
        _GDIPlus_GraphicsDrawImage($hGraphics, $pic, $smCenterX, $smCenterY) ;display scaled image
    EndIf
EndFunc   ;==>ShowImage

Func ShowTrayIcon()
    ConsoleWrite("=ShowTrayIcon=" & @CRLF)
    If $showIcon = "No" Then
        AutoItSetOption("TrayIconHide", 1)
    Else
        AutoItSetOption("TrayIconHide", 0)
    EndIf
EndFunc   ;==>ShowTrayIcon

Func StartWithWindows()
    ConsoleWrite("=StartWithWindows=" & @CRLF)
    If $startWithWindows = "Yes" Then
        If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow") = "" Then
            RegWrite("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow", "REG_SZ", '"' & @ScriptFullPath & '"')
        EndIf
    Else
        If RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow") <> "" Then
            RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run", "Fullscreen Slideshow")
        EndIf
    EndIf
EndFunc   ;==>StartWithWindows

Func CloseWithScreensaver()
    ConsoleWrite("=CloseWithScreensaver=" & @CRLF)
    If $closeWithScreensaver = "Yes" Then
        If $screenSaverOpened = 1 Then
            If ProcessExists("Fullscreen Screensaver.exe") = 0 Then
                Exit
            EndIf
        EndIf
    EndIf
EndFunc   ;==>CloseWithScreensaver

Func RunScreensaver()
    ConsoleWrite("=RunScreensaver=" & @CRLF)
    If $runScreensaver = "Yes" Then
        If ProcessExists("Fullscreen Screensaver.exe") = 0 Then
            Run("D:\Autoit Scripts\Fullscreen Screensaver.exe")
            $screenSaverOpened = 1
        Else
            $screenSaverOpened = 1
        EndIf
    EndIf
EndFunc   ;==>RunScreensaver

Func AlwaysOnTop()
    ConsoleWrite("=AlwaysOnTop=" & @CRLF)
    ;Always keep FSS on top of other windows
    WinSetOnTop("Fullscreen Slideshow", "", 0)
    WinSetOnTop("Fullscreen Slideshow", "", 1)
EndFunc   ;==>AlwaysOnTop

Func LoseFocus()
    ConsoleWrite("=LoseFocus=" & @CRLF)
    ;If Fullscreen Slideshow becomes the active window, change to FSS
    If WinActive("Fullscreen Slideshow", "") <> 0 Then
        WinActivate("FSS", "")
    EndIf
EndFunc   ;==>LoseFocus

Func CheckIfFSSshouldDisplay()
    ConsoleWrite("=CheckIfFSSshouldDisplay=" & @CRLF)
    Local $decided = 0
    Local $returnValue

    ;Is selected window the Desktop?
    $winSize = WinGetClientSize("")
    If $winSize = "" Then ;Prevents non-accessible glitch
        $desktop = 0
        ConsoleWrite("Desktop Selected?: " & $desktop & @CRLF)
    Else
        If $winSize[0] = @DesktopWidth + $smWidth Then ;Desktop
            $desktop = 1
            ConsoleWrite("Desktop Selected?: " & $desktop & @CRLF)
        Else
            $desktop = 0
            ConsoleWrite("Desktop Selected?: " & $desktop & @CRLF)
        EndIf
    EndIf

    ;Where is the active window
    $activeWindowPosition = WinGetPos("[ACTIVE]")
    ConsoleWrite("Active Window Position 0: " & $activeWindowPosition[0] & @CRLF)
    If $smPosition = "Left" Then
        If $activeWindowPosition[0] < 0 Then ;If Active Window is in monitor on left
            If $desktop = 0 Then
                $decided = 1
                $returnValue = "Hide"
                ConsoleWrite("Active Window: On Left" & @CRLF)
                ConsoleWrite("Return: " & $returnValue & @CRLF)
            Else
                $returnValue = "Show"
                ConsoleWrite("Active Window: On Right" & @CRLF)
                ConsoleWrite("Return: " & $returnValue & @CRLF)
            EndIf
        EndIf
    Else ;$smPosition = "Right"
        If $activeWindowPosition[0] > (@DesktopWidth - 1) Or _ ;If Active Window is in monitor on right
                $activeWindowPosition[0] = (@DesktopWidth - 8) Then ;If Active Window is fullscreen
            If $desktop = 0 Then
                $decided = 1
                $returnValue = "Hide"
                ConsoleWrite("Active Window: On Right" & @CRLF)
                ConsoleWrite("Return: " & $returnValue & @CRLF)
            Else
                $returnValue = "Show"
                ConsoleWrite("Return: On Left" & @CRLF)
                ConsoleWrite("Return: " & $returnValue & @CRLF)
            EndIf
        EndIf
    EndIf

    ;Only check if undecided
    If $decided = 0 Then
        ;Where is the mouse located
        If $smPosition = "Left" Then
            If MouseGetPos(0) < 0 Then ;If mouse is in monitor on left
                $decided = 1
                $returnValue = "Hide"
                ConsoleWrite("Mouse Position: On Left" & @CRLF)
                ConsoleWrite("Return: " & $returnValue & @CRLF)
            EndIf
        Else ;$smPosition = "Right"
            If MouseGetPos(0) > @DesktopWidth Then ;If mouse is in monitor on right
                $decided = 1
                $returnValue = "Hide"
                ConsoleWrite("Mouse Position: On Right" & @CRLF)
                ConsoleWrite("Return: " & $returnValue & @CRLF)
            EndIf
        EndIf
        If $decided = 0 Then
            ;Is there a special Window that is active?
            $mPos = _WinAPI_GetMousePos()
            $hwnd = _WinAPI_WindowFromPoint($mPos)
            ;Is VNC active?
            If WinGetTitle($hwnd) = "Cursor Hider" Then
                ConsoleWrite("Cursor Hider Active" & @CRLF)
                $decided = 1

                ;Temporary while VNC is in main window
                ;$returnValue = "Hide"
                $returnValue = "Show"
                ConsoleWrite("Return: " & $returnValue & @CRLF)
            EndIf
        EndIf
    EndIf

    ;Is the Toggle set to hide?
    ;Is Screensaver Off?
    ConsoleWrite("Is Screensaver off?" & @CRLF)
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "ForceFSSOn") = 0 Then
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") = "Hide" Then
            ;Get new image ready while hidden
            CleanupPrevImage()
            GetImageForDisplay()
            ShowImage()
            ;Hide GUI
            $decided = 1
            $returnValue = "Hide"
            ConsoleWrite("Return: " & $returnValue & @CRLF)
        EndIf
    Else
        $returnValue = "Show" ;Screensaver is active
    EndIf

    ;If no issues, then show
    If $decided = 0 Then
        $returnValue = "Show"
        ConsoleWrite("Return: " & $returnValue & @CRLF)
    EndIf
    Return $returnValue
EndFunc   ;==>CheckIfFSSshouldDisplay

Func ShowFSS()
    ConsoleWrite("=ShowFSS=" & @CRLF)
    If $activationMode = "Inactive" Then ;Monitor not in use
        WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
    Else ;$activationMode = "Timer" (Screensaver mode)
        If TimerDiff($screenSaverTimer) > ($ssTimerSeconds) Then
            WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
        EndIf
    EndIf
    ;Redraw GDI
    ConsoleWrite("=FSS calling=" & @CRLF)
    ShowImage()
EndFunc   ;==>ShowFSS

Func HideFSS()
    ConsoleWrite("=HideFSS=" & @CRLF)
    WinSetState("Fullscreen Slideshow", "", @SW_HIDE)
    $refreshImage = 1
    $screenSaverTimer = TimerInit() ;Reset Screensaver Timer
EndFunc   ;==>HideFSS

Func ChangeImage()
    ConsoleWrite("=ChangeImage=" & @CRLF)
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") <> "Monitor Off" Then
        $imageChangedBlack = 0
        If $changeMode = "Refresh" Then
            If $refreshImage = 1 Then
                $refreshImage = 0
                CleanupPrevImage()
                GetImageForDisplay()
                ShowImage()
                GUISetState(@SW_SHOW)
            EndIf
        Else ;$changeMode = "Timer"
            If TimerDiff($imageTimer) > $timerSeconds Then
                $imageTimer = TimerInit() ;Reset Image Change Timer
                CleanupPrevImage()
                GetImageForDisplay()
                ShowImage()
                GUISetState(@SW_SHOW)
            EndIf
        EndIf
    Else ;Use Black Image
        If $imageChangedBlack = 0 Then
            $imageChangedBlack = 1
            CleanupPrevImage()
            GUISetState(@SW_SHOW)
        EndIf
    EndIf
EndFunc   ;==>ChangeImage

Func CleanupPrevImage()
    ConsoleWrite("=CleanupPrevImage=" & @CRLF)
    _GDIPlus_GraphicsDispose($gdiPic)
    _GDIPlus_BitmapDispose($pic)
    GUISetBkColor(0) ;Draw black over previous image

EndFunc   ;==>CleanupPrevImage


Func DisplayTaskbar()
    ConsoleWrite("=DisplayTaskbar=" & @CRLF)
    ;Hide/Show Taskbar
    If MouseGetPos(0) > 0 And MouseGetPos(0) < @DesktopWidth Then ;If mouse is in main monitor
        If MouseGetPos(1) > (@DesktopHeight - 2) Then ;If mouse is at bottom of screen
            ShowTaskBar()
        ElseIf MouseGetPos(1) < (@DesktopHeight - $taskbarSize) Then ;If mouse leaves taskbar area
            If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Blink Taskbar") = 0 Then HideTaskBar()
        EndIf
    Else
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Blink Taskbar") = 0 Then HideTaskBar()
    EndIf
EndFunc   ;==>DisplayTaskbar

Func HideTaskBar()
    ConsoleWrite("=HideTaskBar=" & @CRLF)
    ControlHide('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
    ControlHide('', '', WinGetHandle("[CLASS:Button]"))
EndFunc   ;==>HideTaskBar

Func ShowTaskBar()
    ConsoleWrite("=ShowTaskbar=" & @CRLF)
    ControlShow('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
    ControlShow('', '', WinGetHandle("[CLASS:Button]"))
EndFunc   ;==>ShowTaskBar

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...