Sign in to follow this  
Followers 0
Sori

GDIPlus_ImageResize error 4... ok, so how do I fix it?

15 posts in this topic

My program is supposed to resize an image. It fails and displays a black image on the screen and seems to never really recover from this. After some exploration, I found that I was receiving error #4 with the resize command.

https://www.autoitscript.com/autoit3/docs/libfunctions/_GDIPlus_ImageResize.htm

4: unable to copy image to scaled bitmap

Well that's great and all... but how do I fix it?


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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Show us the code to analyse what's wrong with it.

Error 4 means that the image handle you have provided cannot copied to the local bitmap within the function.

Is your image parameter really a handle?

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Show us the code to analyse what's wrong with it.

Error 4 means that the image handle you have provided cannot copied to the local bitmap within the function.

Is your image parameter really a handle?

;Log File records
        ;smhBmp: D:\Wallpapers\anime-girls-wallpapers-pictures-56.jpg
        ;smGdiPic: 0xD2E72530

    $smhHBmp = $pictureFolder & "\" & $imageList[$smPicName]
    $smGdiPic = _GDIPlus_BitmapCreateFromFile($smhHBmp) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($smhHBmp) ;release GDI bitmap resource because not needed anymore
    $smPic = _GDIPlus_ImageResize($smGdiPic, $smImageWidth, $smImageHeight) ;resize image
    If $smPic = 0 Then
        LogProgram("smPic Error: " & @error)
    EndIf

It takes a bit of time to get the glitch to occur. I'll see if it's that particular image causing trouble.

Some other notes to take into account...

I notice the glitch after my monitor turns off. I intend to do further testing with that. (keeping the monitor on, and seeing it if glitches)

Edited by Sori

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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

First, this line makes no sense

_WinAPI_DeleteObject($smhHBmp) ;release GDI bitmap resource because not needed anymore
$smhHBmp is a string not a GDI handle!

 

Second debug the $smGdiPic line

$smGdiPic = _GDIPlus_BitmapCreateFromFile($smhHBmp) ;convert GDI bitmap to GDI+ bitmap
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $smGdiPic = ' & $smGdiPic & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
What is the return ($smGdiPic) / @error value? Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

First, this line makes no sense

_WinAPI_DeleteObject($smhHBmp) ;release GDI bitmap resource because not needed anymore

$smhHBmp is a string not a GDI handle!

I think that's supposed to be:

_GDIPlus_BitmapDispose()

I never even noticed that I messed up that line >.>

Thank you

I can't find the example script I had found that in... Looking over it, I probably changed something in their code, rendering the line obsolete.

Second debug the $smGdiPic line

$smGdiPic = _GDIPlus_BitmapCreateFromFile($smhHBmp) ;convert GDI bitmap to GDI+ bitmap
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $smGdiPic = ' & $smGdiPic & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
What is the return ($smGdiPic) / @error value?

 

When running without glitches I receive

@@ Debug(388) : $smGdiPic = ;various 0x0#### codes

>Error code: 0

I'll lower my screen shutoff time and let you know what happens.

After the screen cutoff, I waited a few moments then moved my mouse. Everything is still running normally.

It's going to take a bit for the glitch to manifest.

Edited by Sori

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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

I suggest you add an error check whether $smGdiPic is not 0 and @error = 0 -> everything should be work.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I suggest you add an error check whether $smGdiPic is not 0 and @error = 0 -> everything should be work.

 

I'm not sure what you're suggesting.


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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

Log File:

Pre-Adjust
smImageWidth: 1380
smImageHeight: 2262
smWidth: 1280
smHeight: 800
aspectRatioX: 0.927536231884058
aspectRatioY: 0.353669319186561
scaleFactor: 0.353669319186561
New smImageWidth: 488.063660477454
New smImageHeight: 800
smCenterX: 395.968169761273
smCenterY: 0
Resize Image SM
smhBmp: D:Wallpapers1383024136463.jpg
@@ Debug(388) : $smGdiPic = 0xD9918190
>Error code: 0

smGdiPic: 0xD9918190
smhHBmp deleted
smPic Error: 4
smPic: 0
=End GetImageForDisplaySM=

=CleanupPrevImageSM=
=End CleanupPrevImageSM=

=ShowImageSM=
smImageChangeBlack: 0
smhGraphics: 0xF9F89BF8
smPic: 0

Exit


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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I do have a question about GDI's internals...

The image is in a state that it is changing every 2 minutes. There is no disposal of the old image data, it simply writes black over the screen, then replaces the previous variable data with new ones.

Does that create memory leaks or is the data overwritten when the variable is changed?

Edited by Sori

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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

Sorry, but without the script I cannot see what's wrong!


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#include <File.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Timers.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <ImageSearch.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <Date.au3>

;Find Log File information
Local $logCheck = FileOpen(@WorkingDir & "\FSS.txt", 0)
Local $line = FileReadLine($logCheck, 1)
If StringSplit($line, " = ", 1)[2] = "On" Then
    Global $keepLog = 1
Else
    Global $keepLog = 0
EndIf
FileClose($logCheck)

Global $logFile = FileOpen(@WorkingDir & "\FSS Log.txt", 2) ;Overwrites previous contents of file
FileWrite($logFile, "Program Start" & @CRLF)
FileWrite($logFile, "Time: " & _NowTime() & ", " & _NowDate() & @CRLF & @CRLF)
_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 $LoopCount = 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 $smImageChangeBlack = 0
Global $smImageWidth, $smImageHeight, $smpHeight, $smpWidth, $smCenterX, $smCenterY, _
        $smPicName, $activeWindowPosition, $smRefreshImage, $smImageChangeTimer, $smSSMTimer, _
        $startWithWindows, $closeWithScreensaver, $smPic, $smGdiPic, $position
Global $pmImageWidth, $pmImageHeight, $pmpHeight, $pmpWidth, $pmCenterX, $pmCenterY, _
        $pmPicName, $pmSSTimer, $pmPic, $pmGdiPic, $pmSSChangeTimer, $blinkTaskbar, $forceFSSOn
Global $pmGUIhandle, $smGUIhandle, $captureError
Global $changeQuadrant = ($ssChangePercent * 0.01) * ($ssRows * $ssColumns)
Global $screenShotCount = $ssRows * $ssColumns
Global $currentShot = 1
Global $incrementX = @DesktopWidth / $ssColumns
Global $incrementY = @DesktopHeight / $ssRows
Global $currentXpos, $currentYpos, $result
Global $pmChangeImage = 1
Global $screenSaverIsOn = 0
Global $winSize[2]

;Prevents CloseProgram() function on startup
RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Close Program", "REG_SZ", 0)

;Preliminary setup - Creates GUI, displays 1 image
;====================================
GetImageForDisplaySM()
GetImageForDisplayPM()
CreateGUI()
MoveGUIWindow()
$smImageChangeTimer = TimerInit() ;Reset Image Change Timer
$pmSSTimer = TimerInit() ;Reset Primary Screensaver Timer
$pmSSChangeTimer = TimerInit() ;Reset Primary Screensaver Image Change Timer
ShowImageSM()
ShowImagePM()
;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)
    ;======
;~  Local $temp = _Timer_GetIdleTime()
;~  ToolTip("SS: " & $screenSaverIsOn & @CRLF & "Idle: " & $temp, 100, 5)

    ;==========================

    ;These functions are set in settings (FSS.txt)
    ShowTrayIcon() ;Should Tray Icon be shown?
    StartWithWindows() ;Start program with Windows? (doesn't function)
    ;================
    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
    ScreensaverOperations()
    ChangeImageSM()
    DisplayTaskbar()
    CloseProgram()

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

    LogProgram(@CRLF & "=======================================================================")
    Local $logFileSize = FileGetSize($logFile)
    If $logFileSize > 5242880 Then ;5 megabytes
        FileClose($logFile)
        $logFile = FileOpen(@WorkingDir & "\FSS Log.txt", 2) ;Erases log file due to extreme size
    EndIf
    ;Allow CPU to rest
    Sleep(10)
    LogProgram("Time: " & _NowTime() & ", " & _NowDate())
WEnd

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

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

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

    ;Read until the next section
    While $line <> "Fullscreen Screensaver"
        $line = FileReadLine($settingsFile, $lineNumber)
        If $line = "Fullscreen Screensaver" Then
            ExitLoop
        ElseIf $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
            LogProgram("Picture Folder: " & $value)
            $pictureFolder = $value
        ElseIf $description = "Show Tray Icon" Then
            LogProgram("Show Tray Icon: " & $value)
            Global $showIcon = $value
        ElseIf $description = "Secondary Monitor Width" Then
            LogProgram("SM Width: " & $value)
            Global $smWidth = $value
        ElseIf $description = "Secondary Monitor Height" Then
            LogProgram("SM Height: " & $value)
            Global $smHeight = $value
        ElseIf $description = "Monitor Position (Left, Right)" Then
            LogProgram("SM Position: " & $value)
            Global $smPosition = $value
        ElseIf $description = "Activation Mode (Inactive, Timer)" Then
            LogProgram("SM Activation Mode: " & $value)
            Global $smActivationMode = $value
        ElseIf $description = "Screensaver Mode Timer Seconds" Then
            LogProgram("SMSSM Seconds: " & $value)
            Global $smSSMsec = $value
            $smSSMsec = $smSSMsec * 1000 ;Convert to milliseconds
        ElseIf $description = "Change Method (Timer, Refresh)" Then
            LogProgram("SM Change Method: " & $value)
            Global $smChangeMethod = $value
        ElseIf $description = "Image Change Time (In Seconds)" Then
            LogProgram("SM Image Change Seconds: " & $value)
            Global $smImageChangeSec = $value
            $smImageChangeSec = $smImageChangeSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Image Order (Ordered, Random, Random No Repeat)" Then
            LogProgram("SM Image Order: " & $value)
            Global $smImageOrder = $value
        ElseIf $description = "Taskbar Size (Default: 40)" Then
            LogProgram("Taskbar Size: " & $value)
            Global $taskbarSize = $value
        ElseIf $description = "Start with Windows (Yes, No)" Then
            LogProgram("Start with Windows: " & $value)
            Global $startWithWindows = $value
        EndIf
        $lineNumber += 1
    WEnd

    $lineNumber += 2 ;Move past 'Fullscreen Screensaver' line

    ;Read until the next section
    While $line <> ";===================================="
        $line = FileReadLine($settingsFile, $lineNumber)
        LogProgram("lineNumber: " & $lineNumber)
        LogProgram("line: " & $line)
        If $line = ";====================================" Then
            ExitLoop
        EndIf
        ;Split line by Description and value
        $lineSplit = StringSplit($line, " = ", 1)
        $description = $lineSplit[1]
        $value = $lineSplit[2]
        If $description = "Turn Screensaver On (Yes, No)" Then
            LogProgram("Screensaver Turned On?: " & $value)
            Global $screensaverActivated = $value
        ElseIf $description = "Activation Time (In Seconds)" Then
            LogProgram("Screensaver Activation Seconds: " & $value)
            Global $pmSSActivationSec = $value
            $pmSSActivationSec = $pmSSActivationSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Image Change Time (In Seconds)" Then
            LogProgram("Screensaver Image Change Seconds: " & $value)
            Global $pmSSChangeImageSec = $value
            $pmSSChangeImageSec = $pmSSChangeImageSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Taskbar Blink Time (In Seconds)" Then
            Global $taskbarBlinkSec = $value
            $taskbarBlinkSec = $taskbarBlinkSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Rows (Horizontal Cuts)" Then
            LogProgram("Rows: " & $value)
            Global $ssRows = $value
        ElseIf $description = "Columns (Vertical Cuts)" Then
            LogProgram("Columns: " & $value)
            Global $ssColumns = $value
        ElseIf $description = "Percent" Then
            LogProgram("Change %: " & $value)
            Global $ssChangePercent = $value
        ElseIf $description = "Check Count" Then
            LogProgram("Check Count: " & $value)
            Global $ssCheckCount = $value
        EndIf
        $lineNumber += 1
        Sleep(50)
    WEnd

    FileClose($settingsFile)
    LogProgram("=End Get Settings=" & @CRLF)
EndFunc   ;==>GetSettings

Func GetImageForDisplaySM()
    LogProgram("=GetImageForDisplaySM=")
    Local $newPic = 0
    Local $smhHBmp ;for GDI (secondary)
    Local $aspectRatioX, $aspectRatioY, $scaleFactor

    ;Check image folder for count change
    LogProgram("=GetImageForDisplaySM calling=")
    CheckForImageChanges()

    ;Throw away value to prevent error with GetDimensions
    $pmPicName = Random(1, $imageCount, 1)

    ;Secondary Monitor
    ;Images should go in order by file
    LogProgram("Image Order: " & $smImageOrder)
    If $smImageOrder = "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
        $smPicName = $countedImages
        ;Select a random image from the list
    ElseIf $smImageOrder = "Random" Then
        ;Select a random image from the list
        $smPicName = Random(1, $imageCount, 1)
        ;Select a random image, but do not show the same image twice
    Else ;$smImageOrder = "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
            $smPicName = Random(1, $imageCount, 1) ;Pick a random image
            ;Check if image has been shown
            For $y = 1 To $imageCount Step +1
                If $smPicName = $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] = $smPicName ;Save image to shown image list
                ExitLoop ;End loop early
            EndIf
        Next
    EndIf
    LogProgram("(SM) Selected Image SM: " & $imageList[$smPicName])
    LogProgram("(SM - Throw Away)Selected Image PM: " & $imageList[$pmPicName])

    ;Get Dimensions of image
    LogProgram("=GetImageForDisplaySM calling=")
    GetDimensions($imageList[$smPicName], $imageList[$pmPicName])
    $smImageHeight = $smpHeight
    $smImageWidth = $smpWidth

    ;Turn them all into integers. (Fixes glitch that caused some images to skip resizing)
    $smImageHeight = Int($smImageHeight)
    $smImageWidth = Int($smImageWidth)
    $smHeight = Int($smHeight)
    $smWidth = Int($smWidth)

    LogProgram("Pre-Adjust")
    LogProgram("smImageWidth: " & $smImageWidth)
    LogProgram("smImageHeight: " & $smImageHeight)
    LogProgram("smWidth: " & $smWidth)
    LogProgram("smHeight: " & $smHeight)

    ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $smImageWidth > $smWidth = 1 Or $smImageHeight > $smHeight = 1 Then
        ;Calculate Aspect Ratio of image
        $aspectRatioX = $smWidth / $smImageWidth
        $aspectRatioY = $smHeight / $smImageHeight
        LogProgram("aspectRatioX: " & $aspectRatioX)
        LogProgram("aspectRatioY: " & $aspectRatioY)
        If $aspectRatioX < $aspectRatioY Then
            $scaleFactor = $aspectRatioX
        Else
            $scaleFactor = $aspectRatioY
        EndIf
        LogProgram("scaleFactor: " & $scaleFactor)
        $smImageHeight = $smImageHeight * $scaleFactor
        $smImageWidth = $smImageWidth * $scaleFactor
        LogProgram("New smImageWidth: " & $smImageWidth)
        LogProgram("New smImageHeight: " & $smImageHeight)
    Else
        LogProgram("Image is smaller/same size as monitor")
    EndIf

    ;Calculate Center of monitor
    ;(Monitor size - image size) / 2
    $smCenterX = ($smWidth - $smImageWidth) / 2
    $smCenterY = ($smHeight - $smImageHeight) / 2
    LogProgram("smCenterX: " & $smCenterX)
    LogProgram("smCenterY: " & $smCenterY)

    ;Resize the image
    LogProgram("Resize Image SM")
    $smhHBmp = $pictureFolder & "\" & $imageList[$smPicName]
    LogProgram("smhBmp: " & $smhHBmp)
    $smGdiPic = _GDIPlus_BitmapCreateFromFile($smhHBmp) ;convert GDI bitmap to GDI+ bitmap
    LogProgram('@@ Debug(' & @ScriptLineNumber & ') : $smGdiPic = ' & $smGdiPic & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    LogProgram("smGdiPic: " & $smGdiPic)
;~  _GDIPlus_BitmapDispose($smhHBmp) ;release GDI bitmap resource because not needed anymore
;~  LogProgram("smhHBmp deleted")
    $smPic = _GDIPlus_ImageResize($smGdiPic, $smImageWidth, $smImageHeight) ;resize image
    If $smPic = 0 Then
        LogProgram("smPic Error: " & @error)
    EndIf
    LogProgram("smPic: " & $smPic)
    LogProgram("=End GetImageForDisplaySM=" & @CRLF)
EndFunc   ;==>GetImageForDisplaySM

Func GetImageForDisplayPM()
    LogProgram("=GetImageForDisplayPM=")
    Local $newPic = 0
    Local $pmhHBmp ;for GDI (primary)
    Local $aspectRatioX, $aspectRatioY, $scaleFactor

    ;Check image folder for count change
    LogProgram("=GetImageForDisplayPM calling=")
    CheckForImageChanges()

    If $pmChangeImage = 1 Then
        $pmChangeImage = 0
        $pmPicName = Random(1, $imageCount, 1) ;Select a random image from the list for primary
    EndIf

    LogProgram("(PM - Throw Away) Selected Image SM: " & $imageList[$smPicName])
    LogProgram("(PM)Selected Image PM: " & $imageList[$pmPicName])

    ;Get Dimensions of image
    LogProgram("=GetImageForDisplayPM calling=")
    GetDimensions($imageList[$smPicName], $imageList[$pmPicName])
    $pmImageHeight = $pmpHeight
    $pmImageWidth = $pmpWidth

    ;Turn them all into integers. (Fixes glitch that caused some images to skip resizing)
    $pmImageHeight = Int($pmImageHeight)
    $pmImageWidth = Int($pmImageWidth)

    LogProgram("Pre-Adjust")
    LogProgram("pmImageWidth: " & $pmImageWidth)
    LogProgram("pmImageHeight: " & $pmImageHeight)
    LogProgram("pmWidth: " & @DesktopWidth)
    LogProgram("pmHeight: " & @DesktopHeight)

    ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $pmImageWidth > @DesktopWidth Or $pmImageHeight > @DesktopHeight Then
        ;Calculate Aspect Ratio of image
        $aspectRatioX = @DesktopWidth / $pmImageWidth
        $aspectRatioY = @DesktopHeight / $pmImageHeight
        LogProgram("aspectRatioX: " & $aspectRatioX)
        LogProgram("aspectRatioY: " & $aspectRatioY)
        If $aspectRatioX < $aspectRatioY Then
            $scaleFactor = $aspectRatioX
        Else
            $scaleFactor = $aspectRatioY
        EndIf
        $pmImageHeight = $pmImageHeight * $scaleFactor
        $pmImageWidth = $pmImageWidth * $scaleFactor
        LogProgram("New pmImageWidth: " & $pmImageWidth)
        LogProgram("New pmImageHeight: " & $pmImageHeight)
    Else
        LogProgram("Image is smaller/same size as monitor")
    EndIf

    ;Calculate Center of monitor
    ;(Monitor size - image size) / 2
    $pmCenterX = (@DesktopWidth - $pmImageWidth) / 2
    $pmCenterY = (@DesktopHeight - $pmImageHeight) / 2
    LogProgram("pmCenterX: " & $pmCenterX)
    LogProgram("pmCenterY: " & $pmCenterY)

    ;Resize the image
    LogProgram("Resize Image PM")
    $pmhHBmp = $pictureFolder & "\" & $imageList[$pmPicName]
    LogProgram("pmhHBmp: " & $pmhHBmp)
    $pmGdiPic = _GDIPlus_BitmapCreateFromFile($pmhHBmp) ;convert GDI bitmap to GDI+ bitmap
    LogProgram("pmGdiPic: " & $pmGdiPic)
;~  _GDIPlus_BitmapDispose($pmhHBmp) ;release GDI bitmap resource because not needed anymore
;~  LogProgram("pmhHBmp deleted")
    $pmPic = _GDIPlus_ImageResize($pmGdiPic, $pmImageWidth, $pmImageHeight) ;resize image
    LogProgram("Resized pmPic: " & $pmPic)
    LogProgram("=End GetImageForDisplayPM=" & @CRLF)
EndFunc   ;==>GetImageForDisplayPM

Func GetDimensions($smPicName, $pmPicName)
    LogProgram("=GetDimensions=")
    Local $prop, $dArray, $fileSize, $imageDimensionsGDI

    ;Secondary Monitor
    LogProgram("-Secondary Monitor-")
    $path = $pictureFolder & "\" & $smPicName
    LogProgram("Path: " & $path)
    $fileSize = FileGetSize($path)
    LogProgram("File Size: " & $fileSize)
    LogProgram("Registry Size: " & RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size"))
    ;Save information to registry for faster access. Compare size of picture to verify changes to picture
    If $fileSize <> RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size") Then
        LogProgram("File Sizes Do Not Match")
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size", "REG_SZ", $fileSize)
        $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
        $smpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
        $smpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
        _GDIPlus_ImageDispose($imageDimensionsGDI)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Width", "REG_SZ", $smpWidth)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Height", "REG_SZ", $smpHeight)
    Else
        LogProgram("File Sizes Match")
        $smpWidth = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Width")
        $smpHeight = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Height")
        If $smpWidth = "-1" Or $smpHeight = "-1" Then
            LogProgram("Correcting Saved Dimensions")
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size", "REG_SZ", $fileSize)
            $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
            $smpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
            $smpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
            _GDIPlus_ImageDispose($imageDimensionsGDI)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Width", "REG_SZ", $smpWidth)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Height", "REG_SZ", $smpHeight)
        EndIf
    EndIf
    LogProgram("smpWidth: " & $smpWidth)
    LogProgram("smpHeight: " & $smpHeight)

    ;Primary Monitor
    LogProgram("-Primary Monitor-")
    $path = $pictureFolder & "\" & $pmPicName
    LogProgram("Path: " & $path)
    $fileSize = FileGetSize($path)
    LogProgram("File Size: " & $fileSize)
    LogProgram("Registry Size: " & RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size"))
    ;Save information to registry for faster access. Compare size of picture to verify changes to picture
    If $fileSize <> RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size") Then
        LogProgram("File Sizes Do Not Match")
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size", "REG_SZ", $fileSize)
        $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
        $pmpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
        $pmpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
        _GDIPlus_ImageDispose($imageDimensionsGDI)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Width", "REG_SZ", $pmpWidth)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Height", "REG_SZ", $pmpHeight)
    Else
        LogProgram("File Sizes Match")
        $pmpWidth = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Width")
        $pmpHeight = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Height")
        If $pmpWidth = "-1" Or $pmpHeight = "-1" Then
            LogProgram("Correcting Saved Dimensions")
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size", "REG_SZ", $fileSize)
            $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
            $pmpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
            $pmpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
            _GDIPlus_ImageDispose($imageDimensionsGDI)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Width", "REG_SZ", $pmpWidth)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Height", "REG_SZ", $pmpHeight)
        EndIf
    EndIf
    LogProgram("pmpWidth: " & $pmpWidth)
    LogProgram("pmpHeight: " & $pmpHeight)
    LogProgram("=End GetDimensions=" & @CRLF)
EndFunc   ;==>GetDimensions

Func CheckForImageChanges()
    LogProgram("=CheckForImageChanges=")
    Local $newCount = _FileListToArray($pictureFolder)
    LogProgram("Old Count: " & $imageCount)
    LogProgram("New Count: " & $newCount[0])
    If $newCount[0] <> $imageCount Then
        LogProgram("New Images Found")
        $imageList = _FileListToArray($pictureFolder)
        $imageCount = $imageList[0]
        ReDim $imageShown[$imageCount + 1]
    Else
        LogProgram("No New Images")
    EndIf
    LogProgram("=End CheckForImageChanges=" & @CRLF)
EndFunc   ;==>CheckForImageChanges

Func CreateGUI()
    LogProgram("=CreateGUI=")
    ;Hidden GUI for fixing if FSS becomes the active window
    GUICreate("FSS", 0, 0, 0, 0)
    LogProgram("FSS created")
    ;Parent, for window border hide effect
    $GUIHide = GUICreate("hide", 0, 0, 0, 0)
    LogProgram("hide created")
    ;Actual GUI to be used
    ;Slideshow GUI
    Global $smGUI = GUICreate("Fullscreen Slideshow", $smWidth, $smHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the secondary screen
    LogProgram("Fullscreen Slideshow created")
    $smGUIhandle = WinGetHandle("Fullscreen Slideshow", "")
    GUICtrlSetPos($smPic, $smCenterX, $smCenterY)
    GUISetBkColor(0, $smGUIhandle)
    LogProgram("smGUIhandle: " & $smGUIhandle)
    LogProgram("Show smGUI")
    GUISetState(@SW_SHOW, $smGUIhandle) ;Show SM GUI
    ;Screensaver GUI
    Global $pmGUI = GUICreate("Fullscreen Screensaver", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the primary screen
    LogProgram("Fullscreen Screensaver created")
    $pmGUIhandle = WinGetHandle("Fullscreen Screensaver", "")
    LogProgram("pmGUIhandle: " & $pmGUIhandle)
    GUICtrlSetPos($pmPic, $pmCenterX, $pmCenterY)
    GUISetBkColor(0, $pmGUIhandle)
    LogProgram("Hide pmGUI")
    GUISetState(@SW_HIDE, $pmGUIhandle) ;Hide PM GUI
    LogProgram("=End CreateGUI=" & @CRLF)
EndFunc   ;==>CreateGUI

Func MoveGUIWindow()
    LogProgram("=MoveGUIWindow=")
    LogProgram("SM Position: " & $smPosition)
    ;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
    WinMove("Fullscreen Screensaver", "", 0, 0, @DesktopWidth, @DesktopHeight)
    LogProgram("=End MoveGUIWindow=" & @CRLF)
EndFunc   ;==>MoveGUIWindow

Func ShowImageSM()
    LogProgram("=ShowImageSM=")
    LogProgram("smImageChangeBlack: " & $smImageChangeBlack)
    If $smImageChangeBlack = 0 Then
        Local $smhGraphics = _GDIPlus_GraphicsCreateFromHWND($smGUI) ;create a graphics object from a window handle
        _GDIPlus_GraphicsDrawImage($smhGraphics, $smPic, $smCenterX, $smCenterY) ;display scaled image
        LogProgram("smhGraphics: " & $smhGraphics)
        LogProgram("smPic: " & $smPic)
        If $smPic = 0 Then
            MsgBox(0, "smpic", "zero error")
            Exit
        EndIf
        LogProgram("smCenterX: " & $smCenterX)
        LogProgram("smCenterY: " & $smCenterY)
    EndIf
    LogProgram("=End ShowImageSM=" & @CRLF)
EndFunc   ;==>ShowImageSM

Func ShowImagePM()
    LogProgram("=ShowImagePM=")
    Local $pmhGraphics = _GDIPlus_GraphicsCreateFromHWND($pmGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($pmhGraphics, $pmPic, $pmCenterX, $pmCenterY) ;display scaled image
    LogProgram("pmhGraphics: " & $pmhGraphics)
    LogProgram("pmPic: " & $pmPic)
    LogProgram("pmCenterX: " & $pmCenterX)
    LogProgram("pmCenterY: " & $pmCenterY)
    LogProgram("=End ShowImagePM=" & @CRLF)
EndFunc   ;==>ShowImagePM

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

Func StartWithWindows()
    LogProgram("=StartWithWindows=")
    If $startWithWindows = "Yes" Then
        LogProgram("Yes")
        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
        LogProgram("No")
        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
    LogProgram("=End StartWithWindows=" & @CRLF)
EndFunc   ;==>StartWithWindows

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

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

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

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

    ;Where is the active window
    $activeWindowPosition = WinGetPos("[ACTIVE]")
    LogProgram("Active Window Position: " & $activeWindowPosition[0])
    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"
                LogProgram("Active Window: On Left")
                LogProgram("Return: " & $returnValue)
            Else
                $returnValue = "Show"
                LogProgram("Active Window: On Right")
                LogProgram("Return: " & $returnValue)
            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"
                LogProgram("Active Window: On Right")
                LogProgram("Return: " & $returnValue)
            Else
                $returnValue = "Show"
                LogProgram("Active Window: On Left")
                LogProgram("Return: " & $returnValue)
            EndIf
        EndIf
    EndIf

    ;Only check if undecided
    If $decided = 0 Then
        ;Where is the mouse located
        LogProgram("Mouse Position: " & MouseGetPos(0) & ", " & MouseGetPos(1))
        If $smPosition = "Left" Then
            If MouseGetPos(0) < 0 Then ;If mouse is in monitor on left
                $decided = 1
                $returnValue = "Hide"
                LogProgram("Mouse Position: On Left")
                LogProgram("Return: " & $returnValue)
            EndIf
        Else ;$smPosition = "Right"
            If MouseGetPos(0) > @DesktopWidth Then ;If mouse is in monitor on right
                ;Bottom right corner of SM is activation spot
                If MouseGetPos(0) > (@DesktopWidth + $smWidth) - 3 Then
                    If MouseGetPos(1) > $smHeight - 3 Then
                        LogProgram("Mouse Activation Position")
                        LogProgram("Return: " & $returnValue)
                        $decided = 1
                        $returnValue = "Show"
                    Else
                        $decided = 1
                        $returnValue = "Hide"
                        LogProgram("Mouse Position: On Right")
                        LogProgram("Return: " & $returnValue)
                    EndIf
                Else
                    $decided = 1
                    $returnValue = "Hide"
                    LogProgram("Mouse Position: On Right")
                    LogProgram("Return: " & $returnValue)
                EndIf
            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
                LogProgram("Cursor Hider Active")
                $decided = 1

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

    ;Is the Toggle set to hide?
    ;Is Screensaver Off?
    LogProgram("forceFSSOn: " & $forceFSSOn)
    If $forceFSSOn = 0 Then
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") = "Hide" Then
            ;Get new image ready while hidden
            CleanupPrevImageSM()
            GetImageForDisplaySM()
            ShowImageSM()
            ;Hide GUI
            $decided = 1
            $returnValue = "Hide"
            LogProgram("Return: " & $returnValue)
        EndIf
    Else
        $returnValue = "Show" ;Screensaver is active
    EndIf

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

Func ShowFSS()
    LogProgram("=ShowFSS=")
    If $smActivationMode = "Inactive" Then ;Monitor not in use
        WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
    Else ;$smActivationMode = "Timer" (Screensaver mode)
        If TimerDiff($smSSMTimer) > ($smSSMsec) Then
            WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
        EndIf
    EndIf
    ;Redraw GDI
    LogProgram("=ShowFSS calling=")
    ShowImageSM()
    ShowImagePM()
    LogProgram("=End ShowFSS=" & @CRLF)
EndFunc   ;==>ShowFSS

Func HideFSS()
    LogProgram("=HideFSS=")
    WinSetState("Fullscreen Slideshow", "", @SW_HIDE)
    $smRefreshImage = 1
    $smSSMTimer = TimerInit() ;Reset Screensaver Timer
    LogProgram("=End HideFSS=" & @CRLF)
EndFunc   ;==>HideFSS

Func ChangeImageSM()
    LogProgram("=ChangeImageSM=")
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") <> "Monitor Off" Then
        $smImageChangeBlack = 0
        LogProgram("smImageChangeBlack: " & $smImageChangeBlack)
        LogProgram("changeMethod: " & $smChangeMethod)
        If $smChangeMethod = "Refresh" Then
            If $smRefreshImage = 1 Then
                $smRefreshImage = 0
                GetImageForDisplaySM()
                CleanupPrevImageSM()
                ShowImageSM()
                GUISetState(@SW_SHOW, $smGUIhandle)
            EndIf
        Else ;$smChangeMethod = "Timer"
            If TimerDiff($smImageChangeTimer) > $smImageChangeSec Then
                $smImageChangeTimer = TimerInit() ;Reset Image Change Timer
                GetImageForDisplaySM()
                CleanupPrevImageSM()
                ShowImageSM()
                GUISetState(@SW_SHOW, $smGUIhandle)
            EndIf
        EndIf
    Else ;Use Black Image
        If $smImageChangeBlack = 0 Then
            $smImageChangeBlack = 1
            CleanupPrevImageSM()
            GUISetState(@SW_SHOW, $smGUIhandle)
        EndIf
    EndIf
    LogProgram("=End ChangeImageSM=" & @CRLF)
EndFunc   ;==>ChangeImageSM

Func CleanupPrevImageSM()
    LogProgram("=CleanupPrevImageSM=")
    ;_GDIPlus_GraphicsDispose($smGdiPic)
    ;_GDIPlus_BitmapDispose($smPic)
    GUISetBkColor(0, $smGUIhandle) ;Draw black over previous image
    LogProgram("=End CleanupPrevImageSM=" & @CRLF)
EndFunc   ;==>CleanupPrevImageSM

Func CleanupPrevImagePM()
    LogProgram("=CleanupPrevImagePM=")
    ;_GDIPlus_GraphicsDispose($pmGdiPic)
    ;_GDIPlus_BitmapDispose($pmPic)
    GUISetBkColor(0, $pmGUIhandle) ;Draw black over previous image
    LogProgram("=End CleanupPrevImagePM=" & @CRLF)
EndFunc   ;==>CleanupPrevImagePM


Func DisplayTaskbar()
    LogProgram("=DisplayTaskbar=")
    ;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
            LogProgram("DisplayTaskbar calling")
            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
    LogProgram("=End DisplayTaskbar=" & @CRLF)
EndFunc   ;==>DisplayTaskbar

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

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

Func CloseProgram()
    LogProgram("=CloseProgram=")
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Close Program") = 1 Then
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Close Program", "REG_SZ", 0)
        LogProgram("CloseProgram calling")
        CleanupPrevImageSM()
        LogProgram("CloseProgram calling")
        CleanupPrevImagePM()
        LogProgram("GDI Dispose")
        _GDIPlus_GraphicsDispose($smGdiPic)
        _GDIPlus_BitmapDispose($smPic)
        _GDIPlus_GraphicsDispose($pmGdiPic)
        _GDIPlus_BitmapDispose($pmPic)
        LogProgram("GDI Shutdown")
        _GDIPlus_Shutdown()
        LogProgram("GUI Delete")
        GUIDelete($smGUI)
        GUIDelete($pmGUI)
        LogProgram("Program Closed" & @CRLF)
        FileClose($logFile)
        Exit
    EndIf
    LogProgram("Program Not Closed" & @CRLF)
    LogProgram("=End CloseProgram=")
EndFunc   ;==>CloseProgram

Func ScreensaverOperations()
    LogProgram("=ScreensaverOperations=")
    Local $checkCount, $stop
    LogProgram("Screensaver Activated? " & $screensaverActivated)
    LogProgram("Is Screensaver On? " & $screenSaverIsOn)
    If $screensaverActivated = "Yes" Then
        ;Should Screensaver be activated?
        Local $idleTime = _Timer_GetIdleTime()
        LogProgram("Idle Time Seconds: " & ($idleTime / 1000))
        LogProgram("Activation Seconds: " & $pmSSActivationSec)
        If $idleTime > $pmSSActivationSec Then
            If $screenSaverIsOn = 0 Then
                LogProgram("=ScreensaverOperations calling=")
                CaptureScreen() ;Take a screenshot of entire screen (divided into sections)
                Sleep(1000) ;Give time for screenshots to load into hard drive
                $checkCount = 1
                $stop = 0
                While $stop = 0
                    LogProgram("stop: " & $stop)
                    LogProgram("=ScreensaverOperations calling=")
                    $result = CompareScreen() ;Compare screenshots with current desktop
                    LogProgram("result: " & $result)
                    If $result = "Not Changed" Then
                        $checkCount += 1
                        If $checkCount > $ssCheckCount Then ;Check x times before giving up
                            $stop = 1
                        Else
                            Sleep(2000) ;Wait 2 seconds before checking again
                        EndIf
                    Else
                        $stop = 1
                    EndIf
                    Sleep(50)
                WEnd

                ;Activate screensaver
                If $result = "Not Changed" Then
                    LogProgram("=ScreensaverOperations calling=")
                    ShowScreensaver()
                Else ;If the screen has changed
                    LogProgram("=ScreensaverOperations calling=")
                    If CheckForDesktop() = 1 Then ;If Desktop is taking over screen, turn on screensaver anyway
                        ShowScreensaver()
                    Else ;The screen is changing, but the desktop is not active
                        ;Reset Timer (to prevent constant checking)
                        $screensaverActivated = 0
                        _WinAPI_ShowCursor("False")
                        MouseMove(MouseGetPos(0), MouseGetPos(1) - 1, 0) ;Move mouse up 1 pixel
                        MouseMove(MouseGetPos(0), MouseGetPos(1) + 1, 0) ;Move mouse down 1 pixel
                        _WinAPI_ShowCursor("True")
                    EndIf
                EndIf
                ;Erase screenshots
                LogProgram("=ScreensaverOperations calling=")
                ScreensaverCleanUp()
            EndIf ;If $screenSaverIsOn = 0
        Else ;If $idleTime < $pmSSActivationSec
            LogProgram("=ScreensaverOperations calling=")
            HideScreensaver()
        EndIf
        ;===================
        ;Change Image?
        If $screenSaverIsOn = 1 Then
            If TimerDiff($pmSSChangeTimer) > $pmSSChangeImageSec Then
                $pmChangeImage = 1
                LogProgram("=ScreensaverOperations calling=")
                GetImageForDisplayPM()
                CleanupPrevImagePM()
                ShowImagePM()
                GUISetState(@SW_SHOW, $pmGUIhandle)
                $pmSSChangeTimer = TimerInit() ;Reset Image Change Timer
            EndIf
        EndIf
        ;===================
        ;If $screensaverActivated = "No" do nothing
    EndIf
    LogProgram("=End ScreensaverOperations=" & @CRLF)
EndFunc   ;==>ScreensaverOperations

Func ShowScreensaver()
    LogProgram("=ShowScreensaver=")
    WinSetState("Fullscreen Screensaver", "", @SW_SHOW)
    _WinAPI_ShowCursor("False")
    $screenSaverIsOn = 1
    $forceFSSOn = 1
    $blinkTaskbar = 1
    LogProgram("=End ShowScreensaver=" & @CRLF)
EndFunc   ;==>ShowScreensaver

Func HideScreensaver()
    LogProgram("=HideScreensaver=")
    WinSetState("Fullscreen Screensaver", "", @SW_HIDE)
    _WinAPI_ShowCursor("True")
    $screenSaverIsOn = 0
    $forceFSSOn = 0
    If $blinkTaskbar = 1 Then
        $blinkTaskbar = 0
        ControlShow('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
        ControlShow('', '', WinGetHandle("[CLASS:Button]"))
        Sleep($taskbarBlinkSec)
        ControlHide('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
        ControlHide('', '', WinGetHandle("[CLASS:Button]"))
    EndIf
    LogProgram("=End HideScreensaver=" & @CRLF)
EndFunc   ;==>HideScreensaver

Func CaptureScreen()
    LogProgram("=CaptureScreen=")
    $currentShot = 1
    LogProgram("ssRows: " & $ssRows)
    LogProgram("ssColumns: " & $ssColumns)
    LogProgram("currentShot: " & $currentShot)
    ;Vertical
    For $currentYpos = 0 To $ssRows - 1 Step +1
        LogProgram("currentYpos: " & $currentYpos)
        ;Horizontal
        For $currentXpos = 0 To $ssColumns - 1 Step +1
            LogProgram("currentXpos: " & $currentXpos)
            _ScreenCapture_Capture(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp", _
                    ($incrementX * $currentXpos), _
                    ($incrementY * $currentYpos), _
                    ($incrementX * ($currentXpos + 1)), _
                    $incrementY * ($currentYpos + 1), 0)
            If FileExists(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp") = 1 Then
                LogProgram("screensaver " & $currentShot & ".bmp saved")
            Else
                LogProgram("screensaver " & $currentShot & ".bmp save error")
                $captureError = 1
            EndIf
            $currentShot += 1
            LogProgram("currentShot: " & $currentShot)
            Sleep(50)
        Next ;x
        Sleep(50)
    Next ;y

    ;If there is a capture error, retry once
    If $captureError = 1 Then
        LogProgram("Attempt 2")
        $captureError = 0
        $currentShot = 1
        LogProgram("ssRows: " & $ssRows)
        LogProgram("ssColumns: " & $ssColumns)
        LogProgram("currentShot: " & $currentShot)
        ;Vertical
        For $currentYpos = 0 To $ssRows - 1 Step +1
            LogProgram("currentYpos: " & $currentYpos)
            ;Horizontal
            For $currentXpos = 0 To $ssColumns - 1 Step +1
                LogProgram("currentXpos: " & $currentXpos)
                _ScreenCapture_Capture(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp", _
                        ($incrementX * $currentXpos), _
                        ($incrementY * $currentYpos), _
                        ($incrementX * ($currentXpos + 1)), _
                        $incrementY * ($currentYpos + 1), 0)
                If FileExists(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp") = 1 Then
                    LogProgram("screensaver " & $currentShot & ".bmp saved")
                Else
                    LogProgram("screensaver " & $currentShot & ".bmp save error")
                    $captureError = 1
                EndIf
                $currentShot += 1
                LogProgram("currentShot: " & $currentShot)
                Sleep(50)
            Next ;x
            Sleep(50)
        Next ;y
    EndIf
    LogProgram("=End CaptureScreen=" & @CRLF)
EndFunc   ;==>CaptureScreen

Func CompareScreen()
    LogProgram("=CompareScreen=")
    Local $x, $y
    Local $resistance = $changeQuadrant
    If $captureError = 0 Then
        LogProgram("changeQuadrant: " & $resistance)
        $currentShot = 1
        LogProgram("currentShot: " & $currentShot)
        For $currentYpos = 0 To $ssRows - 1 Step +1
            LogProgram("currentYpos: " & $currentYpos)
            For $currentXpos = 0 To $ssColumns - 1 Step +1
                LogProgram("currentXpos: " & $currentXpos)
                If _ImageSearchArea(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp", 1, ($incrementX * $currentXpos), ($incrementY * $currentYpos), ($incrementX * ($currentXpos + 1)), ($incrementY * ($currentYpos + 1)), $x, $y, 0) = 1 Then
                    LogProgram("Image Did Not Change")
                Else
                    LogProgram("Image Changed")
                    $resistance -= 1
                EndIf
                $currentShot += 1
                LogProgram("currentShot: " & $currentShot)
                Sleep(50)
            Next
            Sleep(50)
        Next
        LogProgram("resistance: " & $resistance)
        If $resistance = 0 Then
            LogProgram("Return: Changed")
            Return "Changed"
        ElseIf $resistance < 0 Then
            LogProgram("Return: Changed")
            Return "Changed"
        Else
            LogProgram("Return: Not Changed")
            Return "Not Changed"
        EndIf
    Else
        $captureError = 0
        LogProgram("Return: Skip")
        Return "Skip"
    EndIf
    LogProgram("=End CompareScreen=" & @CRLF)
EndFunc   ;==>CompareScreen

Func CheckForDesktop()
    LogProgram("=CheckForDesktop=")
    Local $x, $y, $desktopFound
    ;Temporary disable until imagesearch glitch is fixed
    ;$desktopFound = _ImageSearchArea("*Trans0xFF00FF Screensaver\Desktop.bmp", 1, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, 0)
    $desktopFound = 0
    LogProgram("desktopFound: " & $desktopFound)
    Return $desktopFound
    LogProgram("=End CheckForDesktop=" & @CRLF)
EndFunc   ;==>CheckForDesktop

Func ScreensaverCleanUp()
    LogProgram("=ScreensaverCleanup=")
    Local $file
    Local $picCount = $ssRows * $ssColumns
    For $file = 1 To $picCount Step +1
        FileDelete(@WorkingDir & "\Screensaver\screensaver " & $file & ".bmp")
        If FileExists(@WorkingDir & "\Screensaver\screensaver " & $file & ".bmp") = 1 Then
            LogProgram("screensaver " & $file & ".bmp delete error")
        Else
            LogProgram("screensaver " & $file & ".bmp deleted")
        EndIf
    Next
    LogProgram("=End ScreensaverCleanup=" & @CRLF)
EndFunc   ;==>ScreensaverCleanUp

Func LogProgram($sentence)
    If $keepLog = 1 Then
        ConsoleWrite($sentence & @CRLF)
        FileWrite($logFile, $sentence & @CRLF)
    EndIf
EndFunc   ;==>LogProgram


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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

Try this
 

#include <File.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <Timers.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <Array.au3>
#include <ImageSearch.au3>
#include <ScreenCapture.au3>
#include <GDIPlus.au3>
#include <Date.au3>

;Find Log File information
Local $logCheck = FileOpen(@WorkingDir & "\FSS.txt", 0)
Local $line = FileReadLine($logCheck, 1)
If StringSplit($line, " = ", 1)[2] = "On" Then
    Global $keepLog = 1
Else
    Global $keepLog = 0
EndIf
FileClose($logCheck)

Global $logFile = FileOpen(@WorkingDir & "\FSS Log.txt", 2) ;Overwrites previous contents of file
FileWrite($logFile, "Program Start" & @CRLF)
FileWrite($logFile, "Time: " & _NowTime() & ", " & _NowDate() & @CRLF & @CRLF)
_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 $LoopCount = 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 $smImageChangeBlack = 0
Global $smImageWidth, $smImageHeight, $smpHeight, $smpWidth, $smCenterX, $smCenterY, _
        $smPicName, $activeWindowPosition, $smRefreshImage, $smImageChangeTimer, $smSSMTimer, _
        $startWithWindows, $closeWithScreensaver, $smPic, $smGdiPic, $position
Global $pmImageWidth, $pmImageHeight, $pmpHeight, $pmpWidth, $pmCenterX, $pmCenterY, _
        $pmPicName, $pmSSTimer, $pmPic, $pmGdiPic, $pmSSChangeTimer, $blinkTaskbar, $forceFSSOn
Global $pmGUIhandle, $smGUIhandle, $captureError
Global $changeQuadrant = ($ssChangePercent * 0.01) * ($ssRows * $ssColumns)
Global $screenShotCount = $ssRows * $ssColumns
Global $currentShot = 1
Global $incrementX = @DesktopWidth / $ssColumns
Global $incrementY = @DesktopHeight / $ssRows
Global $currentXpos, $currentYpos, $result
Global $pmChangeImage = 1
Global $screenSaverIsOn = 0
Global $winSize[2]

;Prevents CloseProgram() function on startup
RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Close Program", "REG_SZ", 0)

;Preliminary setup - Creates GUI, displays 1 image
;====================================
GetImageForDisplaySM()
GetImageForDisplayPM()
CreateGUI()
MoveGUIWindow()
$smImageChangeTimer = TimerInit() ;Reset Image Change Timer
$pmSSTimer = TimerInit() ;Reset Primary Screensaver Timer
$pmSSChangeTimer = TimerInit() ;Reset Primary Screensaver Image Change Timer
ShowImageSM()
ShowImagePM()
;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)
    ;======
;~  Local $temp = _Timer_GetIdleTime()
;~  ToolTip("SS: " & $screenSaverIsOn & @CRLF & "Idle: " & $temp, 100, 5)

    ;==========================

    ;These functions are set in settings (FSS.txt)
    ShowTrayIcon() ;Should Tray Icon be shown?
    StartWithWindows() ;Start program with Windows? (doesn't function)
    ;================
    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
    ScreensaverOperations()
    ChangeImageSM()
    DisplayTaskbar()
    CloseProgram()

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

    LogProgram(@CRLF & "=======================================================================")
    Local $logFileSize = FileGetSize($logFile)
    If $logFileSize > 5242880 Then ;5 megabytes
        FileClose($logFile)
        $logFile = FileOpen(@WorkingDir & "\FSS Log.txt", 2) ;Erases log file due to extreme size
    EndIf
    ;Allow CPU to rest
    Sleep(10)
    LogProgram("Time: " & _NowTime() & ", " & _NowDate())
WEnd

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

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

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

    ;Read until the next section
    While $line <> "Fullscreen Screensaver"
        $line = FileReadLine($settingsFile, $lineNumber)
        If $line = "Fullscreen Screensaver" Then
            ExitLoop
        ElseIf $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
            LogProgram("Picture Folder: " & $value)
            $pictureFolder = $value
        ElseIf $description = "Show Tray Icon" Then
            LogProgram("Show Tray Icon: " & $value)
            Global $showIcon = $value
        ElseIf $description = "Secondary Monitor Width" Then
            LogProgram("SM Width: " & $value)
            Global $smWidth = $value
        ElseIf $description = "Secondary Monitor Height" Then
            LogProgram("SM Height: " & $value)
            Global $smHeight = $value
        ElseIf $description = "Monitor Position (Left, Right)" Then
            LogProgram("SM Position: " & $value)
            Global $smPosition = $value
        ElseIf $description = "Activation Mode (Inactive, Timer)" Then
            LogProgram("SM Activation Mode: " & $value)
            Global $smActivationMode = $value
        ElseIf $description = "Screensaver Mode Timer Seconds" Then
            LogProgram("SMSSM Seconds: " & $value)
            Global $smSSMsec = $value
            $smSSMsec = $smSSMsec * 1000 ;Convert to milliseconds
        ElseIf $description = "Change Method (Timer, Refresh)" Then
            LogProgram("SM Change Method: " & $value)
            Global $smChangeMethod = $value
        ElseIf $description = "Image Change Time (In Seconds)" Then
            LogProgram("SM Image Change Seconds: " & $value)
            Global $smImageChangeSec = $value
            $smImageChangeSec = $smImageChangeSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Image Order (Ordered, Random, Random No Repeat)" Then
            LogProgram("SM Image Order: " & $value)
            Global $smImageOrder = $value
        ElseIf $description = "Taskbar Size (Default: 40)" Then
            LogProgram("Taskbar Size: " & $value)
            Global $taskbarSize = $value
        ElseIf $description = "Start with Windows (Yes, No)" Then
            LogProgram("Start with Windows: " & $value)
            Global $startWithWindows = $value
        EndIf
        $lineNumber += 1
    WEnd

    $lineNumber += 2 ;Move past 'Fullscreen Screensaver' line

    ;Read until the next section
    While $line <> ";===================================="
        $line = FileReadLine($settingsFile, $lineNumber)
        LogProgram("lineNumber: " & $lineNumber)
        LogProgram("line: " & $line)
        If $line = ";====================================" Then
            ExitLoop
        EndIf
        ;Split line by Description and value
        $lineSplit = StringSplit($line, " = ", 1)
        $description = $lineSplit[1]
        $value = $lineSplit[2]
        If $description = "Turn Screensaver On (Yes, No)" Then
            LogProgram("Screensaver Turned On?: " & $value)
            Global $screensaverActivated = $value
        ElseIf $description = "Activation Time (In Seconds)" Then
            LogProgram("Screensaver Activation Seconds: " & $value)
            Global $pmSSActivationSec = $value
            $pmSSActivationSec = $pmSSActivationSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Image Change Time (In Seconds)" Then
            LogProgram("Screensaver Image Change Seconds: " & $value)
            Global $pmSSChangeImageSec = $value
            $pmSSChangeImageSec = $pmSSChangeImageSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Taskbar Blink Time (In Seconds)" Then
            Global $taskbarBlinkSec = $value
            $taskbarBlinkSec = $taskbarBlinkSec * 1000 ;Convert to milliseconds
        ElseIf $description = "Rows (Horizontal Cuts)" Then
            LogProgram("Rows: " & $value)
            Global $ssRows = $value
        ElseIf $description = "Columns (Vertical Cuts)" Then
            LogProgram("Columns: " & $value)
            Global $ssColumns = $value
        ElseIf $description = "Percent" Then
            LogProgram("Change %: " & $value)
            Global $ssChangePercent = $value
        ElseIf $description = "Check Count" Then
            LogProgram("Check Count: " & $value)
            Global $ssCheckCount = $value
        EndIf
        $lineNumber += 1
        Sleep(50)
    WEnd

    FileClose($settingsFile)
    LogProgram("=End Get Settings=" & @CRLF)
EndFunc   ;==>GetSettings

Func GetImageForDisplaySM()
    LogProgram("=GetImageForDisplaySM=")
    Local $newPic = 0
    Local $smhHBmp ;for GDI (secondary)
    Local $aspectRatioX, $aspectRatioY, $scaleFactor

    ;Check image folder for count change
    LogProgram("=GetImageForDisplaySM calling=")
    CheckForImageChanges()

    ;Throw away value to prevent error with GetDimensions
    $pmPicName = Random(1, $imageCount, 1)

    ;Secondary Monitor
    ;Images should go in order by file
    LogProgram("Image Order: " & $smImageOrder)
    If $smImageOrder = "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
        $smPicName = $countedImages
        ;Select a random image from the list
    ElseIf $smImageOrder = "Random" Then
        ;Select a random image from the list
        $smPicName = Random(1, $imageCount, 1)
        ;Select a random image, but do not show the same image twice
    Else ;$smImageOrder = "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
            $smPicName = Random(1, $imageCount, 1) ;Pick a random image
            ;Check if image has been shown
            For $y = 1 To $imageCount Step +1
                If $smPicName = $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] = $smPicName ;Save image to shown image list
                ExitLoop ;End loop early
            EndIf
        Next
    EndIf
    LogProgram("(SM) Selected Image SM: " & $imageList[$smPicName])
    LogProgram("(SM - Throw Away)Selected Image PM: " & $imageList[$pmPicName])

    ;Get Dimensions of image
    LogProgram("=GetImageForDisplaySM calling=")
    GetDimensions($imageList[$smPicName], $imageList[$pmPicName])
    $smImageHeight = $smpHeight
    $smImageWidth = $smpWidth

    ;Turn them all into integers. (Fixes glitch that caused some images to skip resizing)
    $smImageHeight = Int($smImageHeight)
    $smImageWidth = Int($smImageWidth)
    $smHeight = Int($smHeight)
    $smWidth = Int($smWidth)

    LogProgram("Pre-Adjust")
    LogProgram("smImageWidth: " & $smImageWidth)
    LogProgram("smImageHeight: " & $smImageHeight)
    LogProgram("smWidth: " & $smWidth)
    LogProgram("smHeight: " & $smHeight)

    ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $smImageWidth > $smWidth = 1 Or $smImageHeight > $smHeight = 1 Then
        ;Calculate Aspect Ratio of image
        $aspectRatioX = $smWidth / $smImageWidth
        $aspectRatioY = $smHeight / $smImageHeight
        LogProgram("aspectRatioX: " & $aspectRatioX)
        LogProgram("aspectRatioY: " & $aspectRatioY)
        If $aspectRatioX < $aspectRatioY Then
            $scaleFactor = $aspectRatioX
        Else
            $scaleFactor = $aspectRatioY
        EndIf
        LogProgram("scaleFactor: " & $scaleFactor)
        $smImageHeight = $smImageHeight * $scaleFactor
        $smImageWidth = $smImageWidth * $scaleFactor
        LogProgram("New smImageWidth: " & $smImageWidth)
        LogProgram("New smImageHeight: " & $smImageHeight)
    Else
        LogProgram("Image is smaller/same size as monitor")
    EndIf

    ;Calculate Center of monitor
    ;(Monitor size - image size) / 2
    $smCenterX = ($smWidth - $smImageWidth) / 2
    $smCenterY = ($smHeight - $smImageHeight) / 2
    LogProgram("smCenterX: " & $smCenterX)
    LogProgram("smCenterY: " & $smCenterY)

    ;Resize the image
    LogProgram("Resize Image SM")
    $smhHBmp = $pictureFolder & "\" & $imageList[$smPicName]
    LogProgram("smhBmp: " & $smhHBmp)
    $smGdiPic = _GDIPlus_BitmapCreateFromFile($smhHBmp) ;convert GDI bitmap to GDI+ bitmap
    LogProgram('@@ Debug(' & @ScriptLineNumber & ') : $smGdiPic = ' & $smGdiPic & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    LogProgram("smGdiPic: " & $smGdiPic)
;~  _GDIPlus_BitmapDispose($smhHBmp) ;release GDI bitmap resource because not needed anymore
;~  LogProgram("smhHBmp deleted")
    If $smPic Then _GDIPlus_BitmapDispose($smPic)
    $smPic = _GDIPlus_ImageResize($smGdiPic, $smImageWidth, $smImageHeight) ;resize image
    If $smPic = 0 Then
        LogProgram("smPic Error: " & @error)
    EndIf
    _GDIPlus_BitmapDispose($smGdiPic)
    LogProgram("smPic: " & $smPic)
    LogProgram("=End GetImageForDisplaySM=" & @CRLF)
EndFunc   ;==>GetImageForDisplaySM

Func GetImageForDisplayPM()
    LogProgram("=GetImageForDisplayPM=")
    Local $newPic = 0
    Local $pmhHBmp ;for GDI (primary)
    Local $aspectRatioX, $aspectRatioY, $scaleFactor

    ;Check image folder for count change
    LogProgram("=GetImageForDisplayPM calling=")
    CheckForImageChanges()

    If $pmChangeImage = 1 Then
        $pmChangeImage = 0
        $pmPicName = Random(1, $imageCount, 1) ;Select a random image from the list for primary
    EndIf

    LogProgram("(PM - Throw Away) Selected Image SM: " & $imageList[$smPicName])
    LogProgram("(PM)Selected Image PM: " & $imageList[$pmPicName])

    ;Get Dimensions of image
    LogProgram("=GetImageForDisplayPM calling=")
    GetDimensions($imageList[$smPicName], $imageList[$pmPicName])
    $pmImageHeight = $pmpHeight
    $pmImageWidth = $pmpWidth

    ;Turn them all into integers. (Fixes glitch that caused some images to skip resizing)
    $pmImageHeight = Int($pmImageHeight)
    $pmImageWidth = Int($pmImageWidth)

    LogProgram("Pre-Adjust")
    LogProgram("pmImageWidth: " & $pmImageWidth)
    LogProgram("pmImageHeight: " & $pmImageHeight)
    LogProgram("pmWidth: " & @DesktopWidth)
    LogProgram("pmHeight: " & @DesktopHeight)

    ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $pmImageWidth > @DesktopWidth Or $pmImageHeight > @DesktopHeight Then
        ;Calculate Aspect Ratio of image
        $aspectRatioX = @DesktopWidth / $pmImageWidth
        $aspectRatioY = @DesktopHeight / $pmImageHeight
        LogProgram("aspectRatioX: " & $aspectRatioX)
        LogProgram("aspectRatioY: " & $aspectRatioY)
        If $aspectRatioX < $aspectRatioY Then
            $scaleFactor = $aspectRatioX
        Else
            $scaleFactor = $aspectRatioY
        EndIf
        $pmImageHeight = $pmImageHeight * $scaleFactor
        $pmImageWidth = $pmImageWidth * $scaleFactor
        LogProgram("New pmImageWidth: " & $pmImageWidth)
        LogProgram("New pmImageHeight: " & $pmImageHeight)
    Else
        LogProgram("Image is smaller/same size as monitor")
    EndIf

    ;Calculate Center of monitor
    ;(Monitor size - image size) / 2
    $pmCenterX = (@DesktopWidth - $pmImageWidth) / 2
    $pmCenterY = (@DesktopHeight - $pmImageHeight) / 2
    LogProgram("pmCenterX: " & $pmCenterX)
    LogProgram("pmCenterY: " & $pmCenterY)

    ;Resize the image
    LogProgram("Resize Image PM")
    $pmhHBmp = $pictureFolder & "\" & $imageList[$pmPicName]
    LogProgram("pmhHBmp: " & $pmhHBmp)
    $pmGdiPic = _GDIPlus_BitmapCreateFromFile($pmhHBmp) ;convert GDI bitmap to GDI+ bitmap
    LogProgram("pmGdiPic: " & $pmGdiPic)
;~  _GDIPlus_BitmapDispose($pmhHBmp) ;release GDI bitmap resource because not needed anymore
;~  LogProgram("pmhHBmp deleted")
    If $pmPic Then _GDIPlus_BitmapDispose($pmPic)
    $pmPic = _GDIPlus_ImageResize($pmGdiPic, $pmImageWidth, $pmImageHeight) ;resize image
    _GDIPlus_BitmapDispose($pmGdiPic)
    LogProgram("Resized pmPic: " & $pmPic)
    LogProgram("=End GetImageForDisplayPM=" & @CRLF)
EndFunc   ;==>GetImageForDisplayPM

Func GetDimensions($smPicName, $pmPicName)
    LogProgram("=GetDimensions=")
    Local $prop, $dArray, $fileSize, $imageDimensionsGDI

    ;Secondary Monitor
    LogProgram("-Secondary Monitor-")
    $path = $pictureFolder & "\" & $smPicName
    LogProgram("Path: " & $path)
    $fileSize = FileGetSize($path)
    LogProgram("File Size: " & $fileSize)
    LogProgram("Registry Size: " & RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size"))
    ;Save information to registry for faster access. Compare size of picture to verify changes to picture
    If $fileSize <> RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size") Then
        LogProgram("File Sizes Do Not Match")
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size", "REG_SZ", $fileSize)
        $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
        $smpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
        $smpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
        _GDIPlus_ImageDispose($imageDimensionsGDI)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Width", "REG_SZ", $smpWidth)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Height", "REG_SZ", $smpHeight)
    Else
        LogProgram("File Sizes Match")
        $smpWidth = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Width")
        $smpHeight = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Height")
        If $smpWidth = "-1" Or $smpHeight = "-1" Then
            LogProgram("Correcting Saved Dimensions")
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Size", "REG_SZ", $fileSize)
            $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
            $smpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
            $smpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
            _GDIPlus_ImageDispose($imageDimensionsGDI)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Width", "REG_SZ", $smpWidth)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $smPicName & " Height", "REG_SZ", $smpHeight)
        EndIf
    EndIf
    LogProgram("smpWidth: " & $smpWidth)
    LogProgram("smpHeight: " & $smpHeight)

    ;Primary Monitor
    LogProgram("-Primary Monitor-")
    $path = $pictureFolder & "\" & $pmPicName
    LogProgram("Path: " & $path)
    $fileSize = FileGetSize($path)
    LogProgram("File Size: " & $fileSize)
    LogProgram("Registry Size: " & RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size"))
    ;Save information to registry for faster access. Compare size of picture to verify changes to picture
    If $fileSize <> RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size") Then
        LogProgram("File Sizes Do Not Match")
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size", "REG_SZ", $fileSize)
        $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
        $pmpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
        $pmpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
        _GDIPlus_ImageDispose($imageDimensionsGDI)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Width", "REG_SZ", $pmpWidth)
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Height", "REG_SZ", $pmpHeight)
    Else
        LogProgram("File Sizes Match")
        $pmpWidth = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Width")
        $pmpHeight = RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Height")
        If $pmpWidth = "-1" Or $pmpHeight = "-1" Then
            LogProgram("Correcting Saved Dimensions")
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Size", "REG_SZ", $fileSize)
            $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
            $pmpWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
            $pmpHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
            _GDIPlus_ImageDispose($imageDimensionsGDI)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Width", "REG_SZ", $pmpWidth)
            RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow\Pictures", $pmPicName & " Height", "REG_SZ", $pmpHeight)
        EndIf
    EndIf
    LogProgram("pmpWidth: " & $pmpWidth)
    LogProgram("pmpHeight: " & $pmpHeight)
    LogProgram("=End GetDimensions=" & @CRLF)
EndFunc   ;==>GetDimensions

Func CheckForImageChanges()
    LogProgram("=CheckForImageChanges=")
    Local $newCount = _FileListToArray($pictureFolder)
    LogProgram("Old Count: " & $imageCount)
    LogProgram("New Count: " & $newCount[0])
    If $newCount[0] <> $imageCount Then
        LogProgram("New Images Found")
        $imageList = _FileListToArray($pictureFolder)
        $imageCount = $imageList[0]
        ReDim $imageShown[$imageCount + 1]
    Else
        LogProgram("No New Images")
    EndIf
    LogProgram("=End CheckForImageChanges=" & @CRLF)
EndFunc   ;==>CheckForImageChanges

Func CreateGUI()
    LogProgram("=CreateGUI=")
    ;Hidden GUI for fixing if FSS becomes the active window
    GUICreate("FSS", 0, 0, 0, 0)
    LogProgram("FSS created")
    ;Parent, for window border hide effect
    $GUIHide = GUICreate("hide", 0, 0, 0, 0)
    LogProgram("hide created")
    ;Actual GUI to be used
    ;Slideshow GUI
    Global $smGUI = GUICreate("Fullscreen Slideshow", $smWidth, $smHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the secondary screen
    LogProgram("Fullscreen Slideshow created")
    $smGUIhandle = WinGetHandle("Fullscreen Slideshow", "")
    GUICtrlSetPos($smPic, $smCenterX, $smCenterY)
    GUISetBkColor(0, $smGUIhandle)
    LogProgram("smGUIhandle: " & $smGUIhandle)
    LogProgram("Show smGUI")
    GUISetState(@SW_SHOW, $smGUIhandle) ;Show SM GUI
    ;Screensaver GUI
    Global $pmGUI = GUICreate("Fullscreen Screensaver", @DesktopWidth, @DesktopHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the primary screen
    LogProgram("Fullscreen Screensaver created")
    $pmGUIhandle = WinGetHandle("Fullscreen Screensaver", "")
    LogProgram("pmGUIhandle: " & $pmGUIhandle)
    GUICtrlSetPos($pmPic, $pmCenterX, $pmCenterY)
    GUISetBkColor(0, $pmGUIhandle)
    LogProgram("Hide pmGUI")
    GUISetState(@SW_HIDE, $pmGUIhandle) ;Hide PM GUI
    LogProgram("=End CreateGUI=" & @CRLF)
EndFunc   ;==>CreateGUI

Func MoveGUIWindow()
    LogProgram("=MoveGUIWindow=")
    LogProgram("SM Position: " & $smPosition)
    ;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
    WinMove("Fullscreen Screensaver", "", 0, 0, @DesktopWidth, @DesktopHeight)
    LogProgram("=End MoveGUIWindow=" & @CRLF)
EndFunc   ;==>MoveGUIWindow

Func ShowImageSM()
    LogProgram("=ShowImageSM=")
    LogProgram("smImageChangeBlack: " & $smImageChangeBlack)
    If $smImageChangeBlack = 0 Then
        Local $smhGraphics = _GDIPlus_GraphicsCreateFromHWND($smGUI) ;create a graphics object from a window handle
        _GDIPlus_GraphicsDrawImage($smhGraphics, $smPic, $smCenterX, $smCenterY) ;display scaled image
        LogProgram("smhGraphics: " & $smhGraphics)
        LogProgram("smPic: " & $smPic)
        If $smPic = 0 Then
            MsgBox(0, "smpic", "zero error")
            Exit
        EndIf
        LogProgram("smCenterX: " & $smCenterX)
        LogProgram("smCenterY: " & $smCenterY)
        _GDIPlus_GraphicsDispose($smhGraphics)
    EndIf
    LogProgram("=End ShowImageSM=" & @CRLF)
EndFunc   ;==>ShowImageSM

Func ShowImagePM()
    LogProgram("=ShowImagePM=")
    Local $pmhGraphics = _GDIPlus_GraphicsCreateFromHWND($pmGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($pmhGraphics, $pmPic, $pmCenterX, $pmCenterY) ;display scaled image
    LogProgram("pmhGraphics: " & $pmhGraphics)
    LogProgram("pmPic: " & $pmPic)
    LogProgram("pmCenterX: " & $pmCenterX)
    LogProgram("pmCenterY: " & $pmCenterY)
    LogProgram("=End ShowImagePM=" & @CRLF)
EndFunc   ;==>ShowImagePM

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

Func StartWithWindows()
    LogProgram("=StartWithWindows=")
    If $startWithWindows = "Yes" Then
        LogProgram("Yes")
        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
        LogProgram("No")
        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
    LogProgram("=End StartWithWindows=" & @CRLF)
EndFunc   ;==>StartWithWindows

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

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

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

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

    ;Where is the active window
    $activeWindowPosition = WinGetPos("[ACTIVE]")
    LogProgram("Active Window Position: " & $activeWindowPosition[0])
    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"
                LogProgram("Active Window: On Left")
                LogProgram("Return: " & $returnValue)
            Else
                $returnValue = "Show"
                LogProgram("Active Window: On Right")
                LogProgram("Return: " & $returnValue)
            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"
                LogProgram("Active Window: On Right")
                LogProgram("Return: " & $returnValue)
            Else
                $returnValue = "Show"
                LogProgram("Active Window: On Left")
                LogProgram("Return: " & $returnValue)
            EndIf
        EndIf
    EndIf

    ;Only check if undecided
    If $decided = 0 Then
        ;Where is the mouse located
        LogProgram("Mouse Position: " & MouseGetPos(0) & ", " & MouseGetPos(1))
        If $smPosition = "Left" Then
            If MouseGetPos(0) < 0 Then ;If mouse is in monitor on left
                $decided = 1
                $returnValue = "Hide"
                LogProgram("Mouse Position: On Left")
                LogProgram("Return: " & $returnValue)
            EndIf
        Else ;$smPosition = "Right"
            If MouseGetPos(0) > @DesktopWidth Then ;If mouse is in monitor on right
                ;Bottom right corner of SM is activation spot
                If MouseGetPos(0) > (@DesktopWidth + $smWidth) - 3 Then
                    If MouseGetPos(1) > $smHeight - 3 Then
                        LogProgram("Mouse Activation Position")
                        LogProgram("Return: " & $returnValue)
                        $decided = 1
                        $returnValue = "Show"
                    Else
                        $decided = 1
                        $returnValue = "Hide"
                        LogProgram("Mouse Position: On Right")
                        LogProgram("Return: " & $returnValue)
                    EndIf
                Else
                    $decided = 1
                    $returnValue = "Hide"
                    LogProgram("Mouse Position: On Right")
                    LogProgram("Return: " & $returnValue)
                EndIf
            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
                LogProgram("Cursor Hider Active")
                $decided = 1

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

    ;Is the Toggle set to hide?
    ;Is Screensaver Off?
    LogProgram("forceFSSOn: " & $forceFSSOn)
    If $forceFSSOn = 0 Then
        If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") = "Hide" Then
            ;Get new image ready while hidden
            CleanupPrevImageSM()
            GetImageForDisplaySM()
            ShowImageSM()
            ;Hide GUI
            $decided = 1
            $returnValue = "Hide"
            LogProgram("Return: " & $returnValue)
        EndIf
    Else
        $returnValue = "Show" ;Screensaver is active
    EndIf

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

Func ShowFSS()
    LogProgram("=ShowFSS=")
    If $smActivationMode = "Inactive" Then ;Monitor not in use
        WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
    Else ;$smActivationMode = "Timer" (Screensaver mode)
        If TimerDiff($smSSMTimer) > ($smSSMsec) Then
            WinSetState("Fullscreen Slideshow", "", @SW_SHOW)
        EndIf
    EndIf
    ;Redraw GDI
    LogProgram("=ShowFSS calling=")
    ShowImageSM()
    ShowImagePM()
    LogProgram("=End ShowFSS=" & @CRLF)
EndFunc   ;==>ShowFSS

Func HideFSS()
    LogProgram("=HideFSS=")
    WinSetState("Fullscreen Slideshow", "", @SW_HIDE)
    $smRefreshImage = 1
    $smSSMTimer = TimerInit() ;Reset Screensaver Timer
    LogProgram("=End HideFSS=" & @CRLF)
EndFunc   ;==>HideFSS

Func ChangeImageSM()
    LogProgram("=ChangeImageSM=")
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") <> "Monitor Off" Then
        $smImageChangeBlack = 0
        LogProgram("smImageChangeBlack: " & $smImageChangeBlack)
        LogProgram("changeMethod: " & $smChangeMethod)
        If $smChangeMethod = "Refresh" Then
            If $smRefreshImage = 1 Then
                $smRefreshImage = 0
                GetImageForDisplaySM()
                CleanupPrevImageSM()
                ShowImageSM()
                GUISetState(@SW_SHOW, $smGUIhandle)
            EndIf
        Else ;$smChangeMethod = "Timer"
            If TimerDiff($smImageChangeTimer) > $smImageChangeSec Then
                $smImageChangeTimer = TimerInit() ;Reset Image Change Timer
                GetImageForDisplaySM()
                CleanupPrevImageSM()
                ShowImageSM()
                GUISetState(@SW_SHOW, $smGUIhandle)
            EndIf
        EndIf
    Else ;Use Black Image
        If $smImageChangeBlack = 0 Then
            $smImageChangeBlack = 1
            CleanupPrevImageSM()
            GUISetState(@SW_SHOW, $smGUIhandle)
        EndIf
    EndIf
    LogProgram("=End ChangeImageSM=" & @CRLF)
EndFunc   ;==>ChangeImageSM

Func CleanupPrevImageSM()
    LogProgram("=CleanupPrevImageSM=")
    ;_GDIPlus_GraphicsDispose($smGdiPic)
    ;_GDIPlus_BitmapDispose($smPic)
    GUISetBkColor(0, $smGUIhandle) ;Draw black over previous image
    LogProgram("=End CleanupPrevImageSM=" & @CRLF)
EndFunc   ;==>CleanupPrevImageSM

Func CleanupPrevImagePM()
    LogProgram("=CleanupPrevImagePM=")
    ;_GDIPlus_GraphicsDispose($pmGdiPic)
    ;_GDIPlus_BitmapDispose($pmPic)
    GUISetBkColor(0, $pmGUIhandle) ;Draw black over previous image
    LogProgram("=End CleanupPrevImagePM=" & @CRLF)
EndFunc   ;==>CleanupPrevImagePM


Func DisplayTaskbar()
    LogProgram("=DisplayTaskbar=")
    ;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
            LogProgram("DisplayTaskbar calling")
            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
    LogProgram("=End DisplayTaskbar=" & @CRLF)
EndFunc   ;==>DisplayTaskbar

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

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

Func CloseProgram()
    LogProgram("=CloseProgram=")
    If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Close Program") = 1 Then
        RegWrite("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Close Program", "REG_SZ", 0)
        LogProgram("CloseProgram calling")
        CleanupPrevImageSM()
        LogProgram("CloseProgram calling")
        CleanupPrevImagePM()
        LogProgram("GDI Dispose")
        _GDIPlus_GraphicsDispose($smGdiPic)
        _GDIPlus_BitmapDispose($smPic)
        _GDIPlus_GraphicsDispose($pmGdiPic)
        _GDIPlus_BitmapDispose($pmPic)
        LogProgram("GDI Shutdown")
        _GDIPlus_Shutdown()
        LogProgram("GUI Delete")
        GUIDelete($smGUI)
        GUIDelete($pmGUI)
        LogProgram("Program Closed" & @CRLF)
        FileClose($logFile)
        Exit
    EndIf
    LogProgram("Program Not Closed" & @CRLF)
    LogProgram("=End CloseProgram=")
EndFunc   ;==>CloseProgram

Func ScreensaverOperations()
    LogProgram("=ScreensaverOperations=")
    Local $checkCount, $stop
    LogProgram("Screensaver Activated? " & $screensaverActivated)
    LogProgram("Is Screensaver On? " & $screenSaverIsOn)
    If $screensaverActivated = "Yes" Then
        ;Should Screensaver be activated?
        Local $idleTime = _Timer_GetIdleTime()
        LogProgram("Idle Time Seconds: " & ($idleTime / 1000))
        LogProgram("Activation Seconds: " & $pmSSActivationSec)
        If $idleTime > $pmSSActivationSec Then
            If $screenSaverIsOn = 0 Then
                LogProgram("=ScreensaverOperations calling=")
                CaptureScreen() ;Take a screenshot of entire screen (divided into sections)
                Sleep(1000) ;Give time for screenshots to load into hard drive
                $checkCount = 1
                $stop = 0
                While $stop = 0
                    LogProgram("stop: " & $stop)
                    LogProgram("=ScreensaverOperations calling=")
                    $result = CompareScreen() ;Compare screenshots with current desktop
                    LogProgram("result: " & $result)
                    If $result = "Not Changed" Then
                        $checkCount += 1
                        If $checkCount > $ssCheckCount Then ;Check x times before giving up
                            $stop = 1
                        Else
                            Sleep(2000) ;Wait 2 seconds before checking again
                        EndIf
                    Else
                        $stop = 1
                    EndIf
                    Sleep(50)
                WEnd

                ;Activate screensaver
                If $result = "Not Changed" Then
                    LogProgram("=ScreensaverOperations calling=")
                    ShowScreensaver()
                Else ;If the screen has changed
                    LogProgram("=ScreensaverOperations calling=")
                    If CheckForDesktop() = 1 Then ;If Desktop is taking over screen, turn on screensaver anyway
                        ShowScreensaver()
                    Else ;The screen is changing, but the desktop is not active
                        ;Reset Timer (to prevent constant checking)
                        $screensaverActivated = 0
                        _WinAPI_ShowCursor("False")
                        MouseMove(MouseGetPos(0), MouseGetPos(1) - 1, 0) ;Move mouse up 1 pixel
                        MouseMove(MouseGetPos(0), MouseGetPos(1) + 1, 0) ;Move mouse down 1 pixel
                        _WinAPI_ShowCursor("True")
                    EndIf
                EndIf
                ;Erase screenshots
                LogProgram("=ScreensaverOperations calling=")
                ScreensaverCleanUp()
            EndIf ;If $screenSaverIsOn = 0
        Else ;If $idleTime < $pmSSActivationSec
            LogProgram("=ScreensaverOperations calling=")
            HideScreensaver()
        EndIf
        ;===================
        ;Change Image?
        If $screenSaverIsOn = 1 Then
            If TimerDiff($pmSSChangeTimer) > $pmSSChangeImageSec Then
                $pmChangeImage = 1
                LogProgram("=ScreensaverOperations calling=")
                GetImageForDisplayPM()
                CleanupPrevImagePM()
                ShowImagePM()
                GUISetState(@SW_SHOW, $pmGUIhandle)
                $pmSSChangeTimer = TimerInit() ;Reset Image Change Timer
            EndIf
        EndIf
        ;===================
        ;If $screensaverActivated = "No" do nothing
    EndIf
    LogProgram("=End ScreensaverOperations=" & @CRLF)
EndFunc   ;==>ScreensaverOperations

Func ShowScreensaver()
    LogProgram("=ShowScreensaver=")
    WinSetState("Fullscreen Screensaver", "", @SW_SHOW)
    _WinAPI_ShowCursor("False")
    $screenSaverIsOn = 1
    $forceFSSOn = 1
    $blinkTaskbar = 1
    LogProgram("=End ShowScreensaver=" & @CRLF)
EndFunc   ;==>ShowScreensaver

Func HideScreensaver()
    LogProgram("=HideScreensaver=")
    WinSetState("Fullscreen Screensaver", "", @SW_HIDE)
    _WinAPI_ShowCursor("True")
    $screenSaverIsOn = 0
    $forceFSSOn = 0
    If $blinkTaskbar = 1 Then
        $blinkTaskbar = 0
        ControlShow('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
        ControlShow('', '', WinGetHandle("[CLASS:Button]"))
        Sleep($taskbarBlinkSec)
        ControlHide('', '', WinGetHandle("[CLASS:Shell_TrayWnd]"))
        ControlHide('', '', WinGetHandle("[CLASS:Button]"))
    EndIf
    LogProgram("=End HideScreensaver=" & @CRLF)
EndFunc   ;==>HideScreensaver

Func CaptureScreen()
    LogProgram("=CaptureScreen=")
    $currentShot = 1
    LogProgram("ssRows: " & $ssRows)
    LogProgram("ssColumns: " & $ssColumns)
    LogProgram("currentShot: " & $currentShot)
    ;Vertical
    For $currentYpos = 0 To $ssRows - 1 Step +1
        LogProgram("currentYpos: " & $currentYpos)
        ;Horizontal
        For $currentXpos = 0 To $ssColumns - 1 Step +1
            LogProgram("currentXpos: " & $currentXpos)
            _ScreenCapture_Capture(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp", _
                    ($incrementX * $currentXpos), _
                    ($incrementY * $currentYpos), _
                    ($incrementX * ($currentXpos + 1)), _
                    $incrementY * ($currentYpos + 1), 0)
            If FileExists(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp") = 1 Then
                LogProgram("screensaver " & $currentShot & ".bmp saved")
            Else
                LogProgram("screensaver " & $currentShot & ".bmp save error")
                $captureError = 1
            EndIf
            $currentShot += 1
            LogProgram("currentShot: " & $currentShot)
            Sleep(50)
        Next ;x
        Sleep(50)
    Next ;y

    ;If there is a capture error, retry once
    If $captureError = 1 Then
        LogProgram("Attempt 2")
        $captureError = 0
        $currentShot = 1
        LogProgram("ssRows: " & $ssRows)
        LogProgram("ssColumns: " & $ssColumns)
        LogProgram("currentShot: " & $currentShot)
        ;Vertical
        For $currentYpos = 0 To $ssRows - 1 Step +1
            LogProgram("currentYpos: " & $currentYpos)
            ;Horizontal
            For $currentXpos = 0 To $ssColumns - 1 Step +1
                LogProgram("currentXpos: " & $currentXpos)
                _ScreenCapture_Capture(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp", _
                        ($incrementX * $currentXpos), _
                        ($incrementY * $currentYpos), _
                        ($incrementX * ($currentXpos + 1)), _
                        $incrementY * ($currentYpos + 1), 0)
                If FileExists(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp") = 1 Then
                    LogProgram("screensaver " & $currentShot & ".bmp saved")
                Else
                    LogProgram("screensaver " & $currentShot & ".bmp save error")
                    $captureError = 1
                EndIf
                $currentShot += 1
                LogProgram("currentShot: " & $currentShot)
                Sleep(50)
            Next ;x
            Sleep(50)
        Next ;y
    EndIf
    LogProgram("=End CaptureScreen=" & @CRLF)
EndFunc   ;==>CaptureScreen

Func CompareScreen()
    LogProgram("=CompareScreen=")
    Local $x, $y
    Local $resistance = $changeQuadrant
    If $captureError = 0 Then
        LogProgram("changeQuadrant: " & $resistance)
        $currentShot = 1
        LogProgram("currentShot: " & $currentShot)
        For $currentYpos = 0 To $ssRows - 1 Step +1
            LogProgram("currentYpos: " & $currentYpos)
            For $currentXpos = 0 To $ssColumns - 1 Step +1
                LogProgram("currentXpos: " & $currentXpos)
                If _ImageSearchArea(@WorkingDir & "\Screensaver\screensaver " & $currentShot & ".bmp", 1, ($incrementX * $currentXpos), ($incrementY * $currentYpos), ($incrementX * ($currentXpos + 1)), ($incrementY * ($currentYpos + 1)), $x, $y, 0) = 1 Then
                    LogProgram("Image Did Not Change")
                Else
                    LogProgram("Image Changed")
                    $resistance -= 1
                EndIf
                $currentShot += 1
                LogProgram("currentShot: " & $currentShot)
                Sleep(50)
            Next
            Sleep(50)
        Next
        LogProgram("resistance: " & $resistance)
        If $resistance = 0 Then
            LogProgram("Return: Changed")
            Return "Changed"
        ElseIf $resistance < 0 Then
            LogProgram("Return: Changed")
            Return "Changed"
        Else
            LogProgram("Return: Not Changed")
            Return "Not Changed"
        EndIf
    Else
        $captureError = 0
        LogProgram("Return: Skip")
        Return "Skip"
    EndIf
    LogProgram("=End CompareScreen=" & @CRLF)
EndFunc   ;==>CompareScreen

Func CheckForDesktop()
    LogProgram("=CheckForDesktop=")
    Local $x, $y, $desktopFound
    ;Temporary disable until imagesearch glitch is fixed
    ;$desktopFound = _ImageSearchArea("*Trans0xFF00FF Screensaver\Desktop.bmp", 1, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, 0)
    $desktopFound = 0
    LogProgram("desktopFound: " & $desktopFound)
    Return $desktopFound
    LogProgram("=End CheckForDesktop=" & @CRLF)
EndFunc   ;==>CheckForDesktop

Func ScreensaverCleanUp()
    LogProgram("=ScreensaverCleanup=")
    Local $file
    Local $picCount = $ssRows * $ssColumns
    For $file = 1 To $picCount Step +1
        FileDelete(@WorkingDir & "\Screensaver\screensaver " & $file & ".bmp")
        If FileExists(@WorkingDir & "\Screensaver\screensaver " & $file & ".bmp") = 1 Then
            LogProgram("screensaver " & $file & ".bmp delete error")
        Else
            LogProgram("screensaver " & $file & ".bmp deleted")
        EndIf
    Next
    LogProgram("=End ScreensaverCleanup=" & @CRLF)
EndFunc   ;==>ScreensaverCleanUp

Func LogProgram($sentence)
    If $keepLog = 1 Then
        ConsoleWrite($sentence & @CRLF)
        FileWrite($logFile, $sentence & @CRLF)
    EndIf
EndFunc   ;==>LogProgram

Not tested on my system!


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

It's running now, I'll let you know in a few hours.

All you added was to dispose of the pic before resizing?


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

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

Yes, I assume a memory leak has occured caused by the GDI+ functions without disposing the resources.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Several hours later... Hasn't crashed yet.

Next test is to compile it into an exe and run it again. But, I think it was a memory leak.


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

I often get bored and enjoy helping with projects.

Share this post


Link to post
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
Sign in to follow this  
Followers 0