Sori Posted June 20, 2014 Posted June 20, 2014 (edited) I've tried a few different approaches, nothing is working. How do you check if the desktop is the selected window? (the Windows Desktop) Line 299 I've tried using: _WinAPI_GetDesktopWindow (cross-referencing active handle to desktop) Active Window size Active Window Title The debug option shows the desktop as being a negative value, but trying to use the position in an if statement makes autoit angry I can't get anything to work @.@ expandcollapse popup#include <File.au3> #include <GetFileProperty.au3> #Include <GUIConstantsEx.au3> #include <Misc.au3> #include <Timers.au3> #Include <WindowsConstants.au3> #include <WinAPI.au3> ;Only allow one instance of the program to run. If _Singleton("Fullscreen Slideshow", 1) = 0 Then Exit EndIf ;Settings ;==================================== Global Const $pictureFolder = "D:\Wallpapers" Global Const $showIcon = "No" ;Show Tray Icon? Global Const $smWidth = 1280 ;Secondary Monitor Width Global Const $smHeight = 800 ;Secondary Monitor Height Global Const $smPosition = "Left" ;Monitor is on left or right Global Const $activationMode = "Inactive" ;When should the image show (Inactive, Timer) Global Const $ssTimerSeconds = 600 ;If Timer: How long should it wait? (In Seconds) Global Const $changeMode = "Timer" ;How should the image change? (Timer, Refresh) Global Const $timerSeconds = 60 ;If Timer: How often should the image change? (In Seconds) Global Const $randomImages = "Ordered" ;Should the images be in order or random? (Ordered, Random, Random No Repeat) Global Const $taskbarSize = 40 ;(40 is default size of taskbar) ;==================================== Global $ssTimerSet = 0 Global $countedImages = 0 Global $imageWasShown = 1 Global $hidden = 0 Global $VNChidden = 0 Global $taskbarActivationHide = 0 Global $inputDirector = WinGetHandle("Cursor Hider") Global $imageList = _FileListToArray($pictureFolder) Global $imageCount = $imageList[0] Global $imageShown[$imageCount] Global Const $STM_SETIMAGE = 0x0172 Global $currActiveWindow = WinGetHandle("") Global $imageChangedBlack = 0 Global $imageWidth, $imageHeight, $pHeight, $pWidth, $smCenterX, $smCenterY, $count, _ $picName, $activeWindowPosition, $refreshImage, $imageTimer, $screenSaverTimer, $winSize If $showIcon = "No" Then AutoItSetOption("TrayIconHide", 1) EndIf GetImage() ;GUI ;Hidden GUI for fixing if FSS becomes the active window GUICreate("FSS", 0, 0, 0, 0) ;Parent, for taskbar hide effect $GUIHide = GUICreate("hide", 0, 0, 0, 0) ;Actual GUI to be used $GUI = GUICreate("Fullscreen Slideshow", $imageWidth, $imageHeight, 0, 0, BitOR($WS_POPUP, $WS_EX_TOPMOST), -1, $GUIHide) ;GUI is the size of the image $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image GUICtrlSetPos($pic, $smCenterX, $smCenterY) GUISetBkColor(0) GUISetState() MoveWindow() $imageTimer = TimerInit() ;Reset Image Change Timer WinActivate(HWnd($currActiveWindow)) ;Activate window that was previously active ;Main Program While 1 ;Debug ToolTip(CheckIfFSSshouldDisplay() & ":" & $activeWindowPosition[0] & ", " & $activeWindowPosition[1], 100, 5) ;For Debugging ;========================== ;Always keep FSS on top of other windows WinSetOnTop("Fullscreen Slideshow", "", 0) WinSetOnTop("Fullscreen Slideshow", "", 1) ;If Fullscreen Slideshow becomes the active window, change to FSS If WinActive("Fullscreen Slideshow", "") <> 0 Then WinActivate("FSS", "") EndIf ;Should Fullscreen Slideshow be on or off If CheckIfFSSshouldDisplay() = "Show" Then If $activationMode = "Inactive" Then ;Monitor not in use WinSetState("Fullscreen Slideshow", "", @SW_SHOW) Else ;$activationMode = "Timer" (Screensaver mode) If TimerDiff($screenSaverTimer) > ($ssTimerSeconds * 1000) Then WinSetState("Fullscreen Slideshow", "", @SW_SHOW) EndIf EndIf Else WinSetState("Fullscreen Slideshow", "", @SW_HIDE) $refreshImage = 1 $screenSaverTimer = TimerInit() ;Reset Screensaver Timer EndIf ;Changing the Image If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") <> "Monitor Off" Then $imageChangedBlack = 0 If $changeMode = "Refresh" Then If $refreshImage = 1 Then $refreshImage = 0 GetImage() GUICtrlDelete($pic) $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image GUICtrlSetPos($pic, $smCenterX, $smCenterY) GUISetBkColor(0) EndIf Else ;$changeMode = "Timer" If TimerDiff($imageTimer) > ($timerSeconds * 1000) Then GetImage() GUICtrlDelete($pic) $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) ;Pic Control is the size of image GUICtrlSetPos($pic, $smCenterX, $smCenterY) GUISetBkColor(0) $imageTimer = TimerInit() ;Reset Image Change Timer EndIf EndIf Else ;Use Black Image If $imageChangedBlack = 0 Then $imageChangedBlack = 1 GUICtrlDelete($pic) $pic = GUICtrlCreatePic("D:\All Black.jpg", 0, 0, $smWidth, $smHeight) EndIf EndIf ;Hide/Show Taskbar If MouseGetPos(0) > 0 and MouseGetPos(0) < @DesktopWidth Then ;If mouse is in main monitor If MouseGetPos(1) > (@DesktopHeight - 2) Then ;If mouse is at bottom of screen ShowTaskBar() ElseIf MouseGetPos(1) < (@DesktopHeight - $taskbarSize) Then ;If mouse leaves taskbar area HideTaskBar() EndIf Else HideTaskBar() EndIf ;Pre-cautionary in case of changes in Monitor dimensions (if secondary monitor is unplugged) MoveWindow() ;Change count if image folder changes CheckForImageChanges() WEnd Func GetImage() If $randomImages = "Ordered" Then ;Counted Images default is 0 $countedImages += 1 ;If the the counted images surpasses the number of images that are there, then reset the count If $countedImages > $imageCount Then $countedImages = 1 EndIf $picName = $countedImages ElseIf $randomImages = "Random" Then ;Select a random image from the list $picName = Random(1, $imageCount, 1) Else ;$randomImages = "Random No Repeat" For $x = 1 to $imageCount step +1 ;Check entire list of images If $imageWasShown = 1 Then $picName = Random(1, $imageCount, 1) For $y = 1 to $count step +1 ;Check list of shown images If $picName <> $imageShown[$x] Then ;If the image has not been shown $imageWasShown = 0 ExitLoop ;End loop early EndIf Next EndIf Next If $imageWasShown = 1 Then ;Reset list if all images have been shown $picName = Random(1, $imageCount, 1) For $x = 1 to $imageShown[0] Step +1 $imageShown[$x] = "" ;Erase array of images Next EndIf EndIf ;Get Dimensions of image GetDimensions($imageList[$picName]) $imageHeight = $pHeight $imageWidth = $pWidth ;Adjust the image size ;----------------------------------------------- ;If the image is bigger than the screen, adjust it If $imageWidth > $smWidth or $imageHeight > $smHeight Then ;Get aspect ratio $aspectRatioX = $smWidth / $imageWidth ;Aspect ratio = 1280 / image X $aspectRatioY = $smHeight / $imageHeight ;Aspect ratio = 800 / image Y If $aspectRatioX < $aspectRatioY Then ;Image is wide ;New Height $imageHeight = $smWidth * ($imageHeight / $imageWidth) $imageWidth = $smWidth Else ;Image is tall ;New Width $imageWidth = $smHeight * ($imageWidth / $imageHeight) $imageHeight = $smHeight EndIf $imageWidth = Int($imageWidth) ;Convert iW into integer $imageHeight = Int($imageHeight) ;Convert iH into integer EndIf ;Calculate Center ;(Monitor size - image size) / 2 $smCenterX = ($smWidth - $imageWidth) / 2 $smCenterY = ($smHeight - $imageHeight) / 2 EndFunc ;==>GetImage Func GetDimensions($picName) Local $prop, $dArray $path = $pictureFolder & "\" & $picName $prop = _GetFileProperty($path, "Dimensions") $dArray = StringSplit($prop, " x ") $pWidth = Number(StringMid($dArray[1], 2)) $pHeight = Number($dArray[4]) EndFunc ;==>GetDimensions Func MoveWindow() Local $position = WinGetPos("Fullscreen Slideshow") If $smPosition = "Left" Then If $position[0] <> (-1 * $smWidth) or $position[1] <> $smHeight Then WinMove("Fullscreen Slideshow", "", (-1 * $smWidth), 0, $smWidth, $smHeight) EndIf Else If $position[0] <> (@DesktopWidth) or $position[1] <> $smHeight) Then WinMove("Fullscreen Slideshow", "", @DesktopWidth, 0, $smWidth, $smHeight) EndIf EndIf EndFunc ;==>MoveWindow Func HideTaskBar() ControlHide('', '', WinGetHandle("[CLASS:Shell_TrayWnd]")) ControlHide('', '', WinGetHandle("[CLASS:Button]")) EndFunc ;==>HideTaskBar Func ShowTaskBar() ControlShow('', '', WinGetHandle("[CLASS:Shell_TrayWnd]")) ControlShow('', '', WinGetHandle("[CLASS:Button]")) EndFunc ;==>ShowTaskBar Func CheckIfFSSshouldDisplay() Local $decided = 0 ;Where is the mouse located If $smPosition = "Left" Then If MouseGetPos(0) < 0 Then ;If mouse is in monitor on left $decided = 1 Return "Hide" EndIf Else ;$smPosition = "Right" If MouseGetPos(0) > @DesktopWidth Then ;If mouse is in monitor on right $decided = 1 Return "Hide" EndIf EndIf ;Only check if undecided If $decided = 0 Then ;Where is the active window $activeWindowPosition = WinGetPos("[ACTIVE]") If $smPosition = "Left" Then If $activeWindowPosition[0] < 0 Then ;If Active Window is in monitor on left $decided = 1 Return "Hide" EndIf Else ;$smPosition = "Right" If $activeWindowPosition[0] > @DesktopWidth Then ;If mouse is in monitor on right $decided = 1 Return "Hide" EndIf EndIf EndIf If $decided = 0 Then ;Is there a special Window that is active? $mPos = _WinAPI_GetMousePos() $hwnd = _WinAPI_WindowFromPoint ($mPos) If $hwnd = $inputDirector Then $decided = 1 Return "Hide" EndIf EndIf If $decided = 0 Then ;Is the Toggle set to hide? If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") = "Hide" Then Return "Hide" EndIf EndIf ;Is selected window the Desktop? ;If $smPosition = "Left" Then ; If WinActive("") = "" Then ; $decided = 0 ; EndIf ;Else ;$smPosition = "Right" ;No Data available ;EndIf ;If no issues, then show If $decided = 0 Then Return "Show" EndIf EndFunc ;==>CheckIfFSSshouldDisplay Func CheckForImageChanges() Local $newCount = _FileListToArray($pictureFolder) If $newCount[0] <> $imageCount Then $imageList = _FileListToArray($pictureFolder) $imageCount = $imageList[0] EndIf EndFunc ;==>CheckForImageChanges Edited June 20, 2014 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.
Solution Sori Posted June 20, 2014 Author Solution Posted June 20, 2014 (edited) I think I'm just too tired. ;Is selected window the Desktop? $winSize = WinGetClientSize("") If $winSize[0] = @DesktopWidth + $smWidth Then ;Desktop $desktop = 1 Else $desktop = 0 EndIf I also changed all return marks inside the function to pass to a varible called $return instead, then at the end, I have 1 return. It had slipped my mind that if you use a return, the func will stop. I think everything is in order now . expandcollapse popupFunc CheckIfFSSshouldDisplay() Local $decided = 0 Local $return, $desktop ;Is selected window the Desktop? $winSize = WinGetClientSize("") If $winSize[0] = @DesktopWidth + $smWidth Then ;Desktop $desktop = 1 Else $desktop = 0 EndIf ;Where is the mouse located If $smPosition = "Left" Then If MouseGetPos(0) < 0 Then ;If mouse is in monitor on left $decided = 1 $return = "Hide" EndIf Else ;$smPosition = "Right" If MouseGetPos(0) > @DesktopWidth Then ;If mouse is in monitor on right $decided = 1 $return = "Hide" EndIf EndIf ;Only check if undecided If $decided = 0 Then ;Where is the active window $activeWindowPosition = WinGetPos("[ACTIVE]") If $smPosition = "Left" Then If $activeWindowPosition[0] < 0 Then ;If Active Window is in monitor on left If $desktop = 0 Then $decided = 1 $return = "Hide" Else $return = "Show" EndIf EndIf Else ;$smPosition = "Right" If $activeWindowPosition[0] > @DesktopWidth Then ;If mouse is in monitor on right If $desktop = 0 Then $decided = 1 $return = "Hide" Else $return = "Show" EndIf EndIf EndIf EndIf If $decided = 0 Then ;Is there a special Window that is active? $mPos = _WinAPI_GetMousePos() $hwnd = _WinAPI_WindowFromPoint ($mPos) If $hwnd = $inputDirector Then $decided = 1 $return = "Hide" EndIf EndIf If $decided = 0 Then ;Is the Toggle set to hide? If RegRead("HKEY_CURRENT_USER\Software\Fullscreen Slideshow", "Mode") = "Hide" Then $return = "Hide" EndIf EndIf ;If no issues, then show If $decided = 0 Then $return = "Show" EndIf return $return EndFunc ;==>CheckIfFSSshouldDisplay Edited June 20, 2014 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now