Sori Posted May 26, 2014 Share Posted May 26, 2014 GetFileProperty.au3 found here Welp... I'm running into an annoyance with my new program. What this program does is puts a fullscreen image over your extra monitor. If you move your mouse into the extra monitor, the program will vanish and re-appear if you go back to your main monitor. Everything is working fine with the coding. The issue I'm having is with the images themselves. On several images, there are pixels not being drawn. You will see the background color of the GUI in these "holes". I tried setting the ctrl background to white (being that most of the holes appear in a white area), that did nothing to fix the issue. I also checked one of my images for transparent pixels in the area of the tear, this also showed that nothing was wrong with the image file. Any assistance is much appreciated. (Attached are the picture of the damage, and the original picture) (Please note: While the sample image is resized, even images that are not resized show this issue) 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 Black", 1) = 0 Then Exit EndIf ;Settings ;==================================== Global Const $pictureFolder = "D:\Pictures\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, RandomNoRepeat) ;==================================== Global $imageTimer Global $screenSaverTimer Global $ssTimerSet = 0 Global $countedImages = 0 Global $imageWasShown = 1 Global $hidden = 0 Global $VNChidden = 0 Global $inputDirector = WinGetHandle("Cursor Hider") Global $imageList = _FileListToArray($pictureFolder) Global $imageCount = $imageList[0] Global $imageShown[$imageCount] Global $picName Global Const $STM_SETIMAGE = 0x0172 Global $imageWidth, $imageHeight, $pHeight, $pWidth, $smCenterX, $smCenterY, $count If $showIcon = "No" Then AutoItSetOption("TrayIconHide", 1) EndIf GetImageDimensions() ;GUI ;Parent, for taskbar hide effect $GUIHide = GUICreate("hide", 0, 0, 0, 0) ;Actual GUI to be used $GUI = GUICreate("Fullscreen Black", $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() If $smPosition = "Left" Then WinMove("Fullscreen Black", "", (-1 * $smWidth), 0, $smWidth, $smHeight) Else WinMove("Fullscreen Black", "", @DesktopWidth, 0, $smWidth, $smHeight) EndIf $imageTimer = TimerInit() ;Reset Image Change Timer While 1 ;Screensaver function If $activationMode = "Timer" Then If $ssTimerSet = 1 Then If TimerDiff($screenSaverTimer) > ($ssTimerSeconds * 1000) Then WinSetState("Fullscreen Black", "", @SW_SHOW) $hidden = 0 EndIf EndIf EndIf CheckForImageChanges() $pos = _WinAPI_GetMousePos() $hwnd = _WinAPI_WindowFromPoint ($pos) ;If your mouse is in the Input Director Window, hide fullscreen black If $hwnd = $inputDirector Then $VNChidden = 1 WinSetState("Fullscreen Black", "", @SW_HIDE) If $changeMode = "Refresh" Then NewImage() Else ;If VNC caused FSB to hide, then re-show WinSetOnTop("Fullscreen Black", "", 1) If $VNChidden = 1 Then $VNChidden = 0 WinSetState("Fullscreen Black", "", @SW_SHOW) EndIf EndIf $info = GUIGetCursorInfo($GUI) If $info[4] = 3 Then ;If mouse is over Fullscreen Black, hide the window WinSetState("Fullscreen Black", "", @SW_HIDE) $ssTimerSet = 0 If $changeMode = "Refresh" Then NewImage() $hidden = 1 Else If $hidden = 1 Then If $smPosition = "Left" Then If MouseGetPos(0) > 0 Then ;If mouse is in main monitor, show the window If $activationMode= "Inactive" Then WinSetState("Fullscreen Black", "", @SW_SHOW) $hidden = 0 Else ;Screensaver Mode If $ssTimerSet = 0 Then $screenSaverTimer = TimerInit() ;Reset Screensaver Timer $ssTimerSet = 1 EndIf EndIf EndIf Else ;Monitor is on the right If MouseGetPos(0) < @DesktopWidth Then ;If mouse is in main monitor, show the window If $activationMode = "Inactive" Then WinSetState("Fullscreen Black", "", @SW_SHOW) $hidden = 0 Else ;Screensaver Mode If $ssTimerSet = 0 Then $screenSaverTimer = TimerInit() ;Reset Screensaver Timer $ssTimerSet = 1 EndIf EndIf EndIf EndIf EndIf EndIf If $changeMode = "Timer" Then If TimerDiff($imageTimer) > ($timerSeconds * 1000) Then NewImage() $imageTimer = TimerInit() ;Reset Image Change Timer EndIf EndIf Sleep(100) ;Reduce CPU usage WEnd Func NewImage() GetImageDimensions() GUICtrlDelete($pic) $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) GUICtrlSetPos($pic, $smCenterX, $smCenterY) EndFunc ;==>NewImage Func GetImageDimensions() ;Get image from desktop background folder If $randomImages = "Ordered" Then $countedImages += 1 If $countedImages > $imageCount Then $countedImages = 1 EndIf $picName = $countedImages ElseIf $randomImages = "Random" Then $picName = Random(1, $imageCount, 1) Else ;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 ;==>GetImageDimensions 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 CheckForImageChanges() Local $newCount = _FileListToArray($pictureFolder) If $newCount[0] <> $imageCount Then $imageList = _FileListToArray($pictureFolder) $imageCount = $imageList[0] EndIf EndFunc ;==>CheckForImageChanges Damage.bmp If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects. Link to comment Share on other sites More sharing options...
Sori Posted May 26, 2014 Author Share Posted May 26, 2014 If someone has a secondary monitor, could you tell me if you can duplicate the issue? If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects. Link to comment Share on other sites More sharing options...
DigitalFacade82 Posted May 27, 2014 Share Posted May 27, 2014 I am working on something similar myself at the moment and I found your thread (relatively fresh by the looks of it) while searching for how I could go about displaying a gui on the second monitor. I have tidied up your code by adding in the missing declarations for each function and have almost got it to launch, but I have an error with line 36 Global $imageCount = $imageList[0] ==>Subscript used on non-accessible variable. I am not sure about this one, I had a similar problem with another script just recently and I was told to use Ubound to find out about the array being returned. I get it but I hadn't done anything about it, so now I guess I will go digging. May I ask, do you get the same error? I also included the function that is not part of Auto IT release at the bottom of your script. expandcollapse popup#include <File.au3> ;#include <GetFileProperty.au3> #include <GUIConstantsEx.au3> #include <Misc.au3> #include <Timers.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 ;Only allow one instance of the program to run. If _Singleton("Fullscreen Black", 1) = 0 Then Exit EndIf ;Settings ;==================================== Global Const $pictureFolder = "D:\Pictures\Wallpapers" Global Const $showIcon = "Yes" ;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, RandomNoRepeat) ;==================================== Global $imageTimer Global $screenSaverTimer Global $ssTimerSet = 0 Global $countedImages = 0 Global $imageWasShown = 1 Global $hidden = 0 Global $VNChidden = 0 Global $inputDirector = WinGetHandle("Cursor Hider") Global $imageList = _FileListToArray($pictureFolder) Global $imageCount = $imageList[0] Global $imageShown[$imageCount] Global $picName Global Const $STM_SETIMAGE = 0x0172 Global $imageWidth, $imageHeight, $pHeight, $pWidth, $smCenterX, $smCenterY, $count If $showIcon = "No" Then AutoItSetOption("TrayIconHide", 1) EndIf GetImageDimensions() ;GUI ;Parent, for taskbar hide effect Local $GUIHide, $GUI, $pic, $pos, $hwnd, $info $GUIHide = GUICreate("hide", 0, 0, 0, 0) ;Actual GUI to be used $GUI = GUICreate("Fullscreen Black", $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() If $smPosition = "Left" Then WinMove("Fullscreen Black", "", (-1 * $smWidth), 0, $smWidth, $smHeight) Else WinMove("Fullscreen Black", "", @DesktopWidth, 0, $smWidth, $smHeight) EndIf $imageTimer = TimerInit() ;Reset Image Change Timer While 1 ;Screensaver function If $activationMode = "Timer" Then If $ssTimerSet = 1 Then If TimerDiff($screenSaverTimer) > ($ssTimerSeconds * 1000) Then WinSetState("Fullscreen Black", "", @SW_SHOW) $hidden = 0 EndIf EndIf EndIf CheckForImageChanges() $pos = _WinAPI_GetMousePos() $hwnd = _WinAPI_WindowFromPoint($pos) ;If your mouse is in the Input Director Window, hide fullscreen black If $hwnd = $inputDirector Then $VNChidden = 1 WinSetState("Fullscreen Black", "", @SW_HIDE) If $changeMode = "Refresh" Then NewImage() Else ;If VNC caused FSB to hide, then re-show WinSetOnTop("Fullscreen Black", "", 1) If $VNChidden = 1 Then $VNChidden = 0 WinSetState("Fullscreen Black", "", @SW_SHOW) EndIf EndIf $info = GUIGetCursorInfo($GUI) If $info[4] = 3 Then ;If mouse is over Fullscreen Black, hide the window WinSetState("Fullscreen Black", "", @SW_HIDE) $ssTimerSet = 0 If $changeMode = "Refresh" Then NewImage() $hidden = 1 Else If $hidden = 1 Then If $smPosition = "Left" Then If MouseGetPos(0) > 0 Then ;If mouse is in main monitor, show the window If $activationMode = "Inactive" Then WinSetState("Fullscreen Black", "", @SW_SHOW) $hidden = 0 Else ;Screensaver Mode If $ssTimerSet = 0 Then $screenSaverTimer = TimerInit() ;Reset Screensaver Timer $ssTimerSet = 1 EndIf EndIf EndIf Else ;Monitor is on the right If MouseGetPos(0) < @DesktopWidth Then ;If mouse is in main monitor, show the window If $activationMode = "Inactive" Then WinSetState("Fullscreen Black", "", @SW_SHOW) $hidden = 0 Else ;Screensaver Mode If $ssTimerSet = 0 Then $screenSaverTimer = TimerInit() ;Reset Screensaver Timer $ssTimerSet = 1 EndIf EndIf EndIf EndIf EndIf EndIf If $changeMode = "Timer" Then If TimerDiff($imageTimer) > ($timerSeconds * 1000) Then NewImage() $imageTimer = TimerInit() ;Reset Image Change Timer EndIf EndIf Sleep(100) ;Reduce CPU usage WEnd Func NewImage() GetImageDimensions() GUICtrlDelete($pic) $pic = GUICtrlCreatePic($pictureFolder & "\" & $imageList[$picName], 0, 0, $imageWidth, $imageHeight) GUICtrlSetPos($pic, $smCenterX, $smCenterY) EndFunc ;==>NewImage Func GetImageDimensions() Local $aspectRatioX, $aspectRatioY ;Get image from desktop background folder If $randomImages = "Ordered" Then $countedImages += 1 If $countedImages > $imageCount Then $countedImages = 1 EndIf $picName = $countedImages ElseIf $randomImages = "Random" Then $picName = Random(1, $imageCount, 1) Else ;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 ;==>GetImageDimensions Func GetDimensions($picName) Local $prop, $dArray, $path $path = $pictureFolder & "\" & $picName $prop = _GetFileProperty($path, "Dimensions") $dArray = StringSplit($prop, " x ") $pWidth = Number(StringMid($dArray[1], 2)) $pHeight = Number($dArray[4]) EndFunc ;==>GetDimensions Func CheckForImageChanges() Local $newCount = _FileListToArray($pictureFolder) If $newCount[0] <> $imageCount Then $imageList = _FileListToArray($pictureFolder) $imageCount = $imageList[0] EndIf EndFunc ;==>CheckForImageChanges ;=============================================================================== ; ; Description: Returns the requested property or an array of all properties ; for the specified file. ; Syntax: _GetFileProperty( $sPath, optional $sProp ) ; Parameter(s): $sPath - Path and filename of the file to query ; $sProp - (optional) Name of property to return ; if not specified will return array of all properties ; Requirement(s): AutoIt 3.2 or higher ; Return Value(s): On Success - Returns string value of property OR ; Returns 2 dimensional array (property name,value) ; On Failure - Returns nothing ; @error = 1 - file does not exist ; @error = 2 - unable to get property ; Author(s): Sean Hart (autoit AT hartmail DOT ca) ; (idea from GetExtProperty by Simucal, thanks) ; Note(s): Special ; ;=============================================================================== Func _GetFileProperty($sPath, $sProp = "") ; Declare local variables Local $sFile, $sDir, $oShell, $oDir, $oFile, $i, $count, $aProps[1][3] ; Init counter used for array of properties $count = 0 ; Check file exists first If Not FileExists($sPath) Then SetError(1) Return Else ; Pull file name and directory from full file path $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1)) $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1))) ; Create required objects $oShell = ObjCreate("shell.application") $oDir = $oShell.NameSpace($sDir) $oFile = $oDir.Parsename($sFile) ; Loop through 99 possible property numbers (allows for future additions to property fields) For $i = 0 to 99 ; If no property specified then add to array If ($sProp = "") Then ; Only add if property name is not blank If ($oDir.GetDetailsOf($oDir.Items, $i) <> "") Then ; Increase counter and redimension array $count = $count + 1 ReDim $aProps[$count + 1][3] ; Add property name and value to array $aProps[$count][1] = $oDir.GetDetailsOf($oDir.Items, $i) $aProps[$count][2] = $oDir.GetDetailsOf($oFile, $i) EndIf ; If property name matches property being requested, return value ElseIf $oDir.GetDetailsOf($oDir.Items, $i) = $sProp Then Return $oDir.GetDetailsOf($oFile, $i) EndIf Next ; If array was populated return array, otherwise return error 2 If $count > 0 Then Return $aProps Else SetError(2) Return EndIf EndIf EndFunc ;==>_GetFileProperty  I am not sure what you are trying to do with the first part but thought that these might help solve some of the variables?  ; I tested this below by pointing to a known directory on my PC containing pictures Global $pictureFolder = "D:\Pictures\Wallpapers" ; Generate a file list array from the directory Global $imageList = _FileListToArray($pictureFolder, "*.*", 1) ; Check if there are any files in the list generated If Not UBound($imageList) Then Exit MsgBox(16, "Error", "No files found!", 5) ; Borrowed from UEZ - filter the file list for just the image formats $i = 1 Do $chk = StringRegExp($imageList[$i], "(?i:.*\.jpg|.*\.png|.*\.bmp|.*\.gif)", 3) If @error Then _ArrayDelete($imageList, $i) $i -= 1 EndIf $i += 1 Until $i = UBound($imageList) ; Check if the list of files contains images If UBound($imageList) = 1 Then Exit MsgBox(16, "Error", "No images found!", 5) ; Delete the first element from the array because it is not needed in this case ; Uncomment the next line to see what I mean ;_ArrayDisplay($imageList, @TAB , ""); Array before removing the first element _ArrayDelete($imageList, 0) ; So now Global $imageList is solved ; Use this to display the result _ArrayDisplay($imageList, @TAB , ""); Array after removing the first element ;Uncomment below to solve for the Global $imageCount - I am using MsgBox to just display the result ;Global $imageCount = UBound($imageList,1)) MsgBox($MB_SYSTEMMODAL, "", UBound($imageList,1)) Link to comment Share on other sites More sharing options...
Sori Posted May 27, 2014 Author Share Posted May 27, 2014 Your modified version of the code is working on my computer. Did you change the picture folder setting that you are using to the correct one for your computer? When you talk about the "first part" of my code, I assume you are talking about Input Director and VNC. I run a second computer and have it connected to my main computer via a virtual KVM switch. VNC is used to remote view the secondary computer, which I use my secondary monitor for. (Therefore I need to minimize the images) and input director takes control of the mouse and keyboard. (Redirecting my input to the secondary computer) After much experimentation, I found that when my mouse is in the secondary computer, it is inside a program called, "Cursor Hider". As for your second program. It works perfectly on my computer. Due note though: I have 96 files in my folder. Upon exit, I receive a message box stating 96. Your count starts at 0, so it shows 95. Just something to be aware of to prevent out of bounds errors. If you need help with your stuff, feel free to get me on my Skype. I often get bored and enjoy helping with projects. Link to comment Share on other sites More sharing options...
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