Jump to content

Strange behavior GUIGetMsg


 Share

Recommended Posts

Local $hGUI = GUICreate("", $wSize[$nFac], $hSize, -1,-1, 0x00C00000, 0x00000200)
    
    For $i = 1 To $nFold    ;Create folder buttons
        $Count += 1
        
        For $j = 1 To $nFac
            If $Count = $j Then $x = $iCont[$j]
        Next
        
        If $Count = $nFac Then $Count = 0
        If $i > $nFac AND $x = 25 Then $y += 35
        $Btn[$i] = GUICtrlCreateButton($iFold[$i], $x,  $y, 100, 25)
    Next
    
    $Btn[0] = GUICtrlCreateButton("Cancel", $canBtn[$nFac], $hSize-45, 75, 25, 0x0001)
    
Func _SelectFolder()
    GUISetState(@SW_SHOW, $hGUI)
    
    While 1
        WinActivate($hGUI)
        ToolTip("")
        $iMsg = GUIGetMsg()
        $cInfo = GUIGetCursorInfo()
        
        If NOT @error Then
            $bTxt = GUICtrlRead($cInfo[4])        
            If StringLen($bTxt) > 18 Then ToolTip($bTxt)
        EndIf
        
        For $i = 0 To $nFold
            If $iMsg = $Btn[$i] Then
                $fPos = $i
                If $fPos > 0 Then ExitLoop 2
                _EndProgram()
            ElseIf _IsPressed("1B", $hDLL) Then
                Sleep(250)
                _EndProgram()
            EndIf
        Next
    WEnd
    
    ToolTip("")
    GUISetState(@SW_HIDE, $hGUI)
EndFunc

When selecting the "cancel" button there is instant action or a delay of several seconds.  Selecting other buttons causes no delay.

There is no pattern to the time of delay.  There is no failure.  Eventually the script will end.  The delay occurs when I select other buttons first.

After stopping a process, the GUI displays again for another selection.  I can select other buttons multiple times with no issues until I am ready to cancel the script.

I placed MsgBox both outside and inside the "If $iMsg = $Btn[$i]" expression and compared both values.  The values looked okay.  The MsgBox inside the expression

would not display until the script decided to move on.  Again, this only occurs with the "cancel" button.

Link to comment
Share on other sites

  • Moderators

BackHomeAgain,

Too much missing from that code to make it runnable. Please post something which do4es run "out of the box" and demonstrates the same behaviour.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#NoTrayIcon
#include-once
#include <Misc.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>
#include <array.au3>

Local $key1 = "HKCU\Control Panel\Desktop", $key2 = "HKCU\Control Panel\Colors"
Local $val1 = "Wallpaper", $val2 = "Background", $hDLL = "user32.dll"
Local $wP = RegRead($key1,$val1), $bG = RegRead($key2,$val2)
Local $tBar = "[CLASS:Shell_TrayWnd]", $pMan = ControlGetHandle("Program Manager","",1)
Local $dt_W = @DesktopWidth, $dt_H = @DesktopHeight
Local $bGcolor = 0x000000, $tpValue = 0, $wlPaper = "", $windLst = "#m"
Local $style = 0x80000000, $fPath, $fRead, $wFile

;Create full screen window to prevent right click desktop context menu.

Local $iGUI = GUICreate("", $dt_W+10, $dt_H+10, -1, -1, $style)
GuiSetState()
WinSetTrans($iGUI, "", 1)  ;Make window invisible.

;Get list of folder(s) plus level one sub folders.
;The function collects the folders in alphabetical order.

Local $iFold = _FileListToArrayRec(@ScriptDir, "*", 2, -1, 1) 

If @error Then
    MsgBox(0,"Error","Error retrieving folders.")
    Exit
EndIf

;File format: The folder name followed by the image file number position.
;A comma is used as the delimiter.

Local $tPath = @ScriptDir & "\" & "Temp.txt"
Local $nPath = @ScriptDir & "\" & "ImagePosition.txt"
Local $nFile = FileOpen($nPath)

If @error = -1 Then
    MsgBox(0,"Error","Unable to open file.")
    Exit
EndIf

;Ensure folder names are alphabetical in "ImagePosition.txt"

_FileSortLines($nPath, $tPath)
FileCopy($tPath, $nPath, 1)

Local $gHWnd, $gHWnd_, $iWidth_ = 0, $iHeight_ = 0, $FrBk = 1, $hImage
Local $sColors[2], $nFold = $iFold[0], $rFold, $Btn[$iFold[0]+1]
Local $ff, $CT = 0, $sOne = 0, $fPos, $fList, $nList, $LineCnt

;Check for missing folders and invalid data.

$LineCnt = _FileCountLines($nPath)
If $LineCnt = 0 OR $LineCnt <> $nFold Then _Reset()

For $i = 1 To $LineCnt
    $rFold = StringSplit(FileReadLine($nFile), ",")
    If @error OR StringIsDigit($rFold[2]) = 0 Then ExitLoop
        
    For $j = 1 To $nFold
        If StringCompare($rFold[1], $iFold[$j], 1) = 0 Then $CT += 1
    Next
Next
    
If $CT <> $nFold Then _Reset()            
_GDIPlus_Startup()

If $nFold = 1 Then   ;Single folder
    $sOne = 1
    $fPos = 1
    $fPath = $iFold[1]
    $fList = _FileListToArray($fPath)
    $nList = $fList[0]
Else
    ;Set GUI window height and width based on number of folders.
    
    Local $iMsg, $x, $y = 25, $iNum = $nFold, $nFac, $fPass = 0, $cInfo, $bTxt
    Local $wSize[7] = ["", "", 262, 377, 492, 607, 722] 
    Local $canBtn[7] = ["", "", 95, 150, 210, 265, 325] 
    Local $iCont[7] = ["", 25, 140, 255, 370, 485, 600]
        
    If $iNum <= 20 Then $nFac = 2
    If $iNum > 20 AND $iNum <= 40 Then $nFac = 3
    If $iNum > 40 AND $iNum <= 60 Then $nFac = 4
    If $iNum > 60 AND $iNum <= 80 Then $nFac = 5
    If $iNum > 80 Then $nFac = 6
    
    StringSplit(String($iNum/$nFac), ".")   ;Always round up number
    If NOT @error Then $iNum += 1
    Local $hSize = (($iNum/$nFac)*35)+85, $Count = 0
    
    If $hSize >= $dt_H Then 
        MsgBox(0,"Error","GUI Window too large for Screen.")
        Exit
    EndIf
    
    Local $hGUI = GUICreate("", $wSize[$nFac], $hSize, -1,-1, 0x00C00000, 0x00000200)
    
    For $i = 1 To $nFold    ;Create folder buttons
        $Count += 1
        
        For $j = 1 To $nFac
            If $Count = $j Then $x = $iCont[$j]
        Next
        
        If $Count = $nFac Then $Count = 0
        If $i > $nFac AND $x = 25 Then $y += 35
        $Btn[$i] = GUICtrlCreateButton($iFold[$i], $x,  $y, 100, 25)
    Next
    
    $Btn[0] = GUICtrlCreateButton("Cancel", $canBtn[$nFac], $hSize-45, 75, 25, 0x0001)

    ;Setup window title bar color.
    
    Local $aElements[2] = [2, 27], $aColors[2] = [Dec("ffff00"), Dec("00ffff")]
    $sColors[0] = _WinAPI_GetSysColor($aElements[0])
    $sColors[1] = _WinAPI_GetSysColor($aElements[1])
    DllCall("UxTheme.dll", "int", "SetWindowTheme","hwnd",$hGUI,"wstr",0,"wstr",0)
    _WinAPI_SetSysColors($aElements, $aColors)
    
    _SelectFolder()
    $fPath = $iFold[$fPos]
    $fList = _FileListToArray($fPath)
    
    If @error Then
        MsgBox(0,"Error","No files found in folder.")
        
        If $fPass Then
            _SelectAgain()
        Else
            _EndProgram()
        EndIf
    EndIf
    
    $nList = $fList[0]
    _CheckFolder()
    FileClose($nFile) 
    $fPass = 1
EndIf

_HideShowTask(1)
_DisplayImage()

;====================================== FUNCTIONS =====================================

Func _FileSortLines($hFileIn, $hFileOut)
    Local $sReadFile = FileRead($hFileIn), $sWrite, $aLines
    Local $avArray = StringSplit(StringStripCR($sReadFile), @LF)
    _ArraySort($avArray, 0, 1)
    
    For $i = 1 To $avArray[0]
        $sWrite &= $avArray[$i] & @CRLF
    Next
    
    FileClose(FileOpen($hFileOut, 2))
    FileWrite($hFileOut, StringTrimRight($sWrite, StringLen(@CRLF)))
    
    ;Descending order creates an unwanted blank first line when sorting.
    
    _FileReadToArray($hFileOut, $aLines)   ;Delete blank line(s).

    For $i = $aLines[0] To 1 Step -1
        If $aLines[$i] = "" Then
            _ArrayDelete($aLines, $i)
        EndIf
    Next

    _FileWriteFromArray($hFileOut, $aLines, 1)
    Return $hFileOut
EndFunc

Func _SelectFolder()
    GUISetState(@SW_SHOW, $hGUI)
    
    While 1
        WinActivate($hGUI)
        ToolTip("")
        $iMsg = GUIGetMsg()
        $cInfo = GUIGetCursorInfo()
        
        If NOT @error Then
            $bTxt = GUICtrlRead($cInfo[4])        
            If StringLen($bTxt) > 18 Then ToolTip($bTxt)
        EndIf
        
        For $i = 0 To $nFold
            If $iMsg = $Btn[$i] Then
                $fPos = $i
                If $fPos > 0 Then ExitLoop 2
                _EndProgram()
            ElseIf _IsPressed("1B", $hDLL) Then
                Sleep(250)
                _EndProgram()
            EndIf
        Next
    WEnd
    
    ToolTip("")
    GUISetState(@SW_HIDE, $hGUI)
EndFunc

Func _CheckFolder()
    Global $FD = 0
    
    For $i = 1 To $nList
        $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$i])
    
        If NOT @error Then
            $FD = 1
            ExitLoop
        EndIf
    Next

    If $FD = 0 Then
        MsgBox(0,"Error","No images found in folder.")
        
        If $fPass Then
            _SelectAgain()
        Else
            _EndProgram()
        EndIf
    EndIf
EndFunc

Func _SelectAgain()
    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    If $FD Then _Fade($gHWnd, 255, 0, -2, 10)
    _SelectFolder()
    $fPath = $iFold[$fPos]
    $fList = _FileListToArray($fPath)
    $nList = $fList[0]
    _CheckFolder()    
    _DisplayImage()
EndFunc

Func _DisplayImage()
    $rFold = StringSplit(FileReadLine(FileOpen($nPath), $fPos), ",")
    Global $fNum = $rFold[2] -1
    If $fNum < 0 OR $fNum > $nList Then $fNum = 0

    While 1
        If $FrBk Then
            If $fNum = $nList Then $fNum = 0
            $fNum += 1
        Else
            $fNum -= 1 
            If $fNum = 0 Then $fNum = $nList
        EndIf
    
        ;Display the image/picture.
    
        $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$fNum])
        If NOT @error Then _Images($hImage)
    WEnd
EndFunc

Func _Images($hImage)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)  
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage) 
 
    If $iHeight > $dt_H Then
        $ff = $iHeight/$dt_H        
        If ($iWidth/$ff) > $dt_W Then $ff = $iWidth/$dt_W
        $iWidth = $iWidth/$ff
        $iHeight = $iHeight/$ff
    Else
        $ff = $dt_H/$iHeight        
        If ($iWidth*$ff) > $dt_W Then $ff = $dt_W/$iWidth
        $iWidth = $iWidth*$ff
        $iHeight = $iHeight*$ff
    EndIf

    ;Create window as place holder for the image/picture.
    
    If $iWidth < $iWidth_ OR $iHeight < $iHeight_ Then _Fade($gHWnd_, 254, 0, -5, 10)    
    $gHWnd = GUICreate("", $iWidth, $iHeight, -1, -1, $style)
    GUISetState()
    WinSetTrans($gHWnd, "", 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($gHWnd)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)    
    _Fade($gHWnd, 0, 255, 1, 10)
    _Sleep(4000)
    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    $gHWnd_ = $gHWnd
    $iWidth_ = $iWidth 
    $iHeight_ = $iHeight
EndFunc

Func _Sleep($delay)
    Local $tDelay = TimerInit()    

    While TimerDiff($tDelay) < $delay
        If _IsPressed("01", $hDLL) OR _IsPressed("1B", $hDLL) Then
            Sleep(250)
            If $sOne Then
                _EndProgram()
            Else
                _UpDate()
                _SelectAgain()
            EndIf
        ElseIf _IsPressed("06", $hDLL) Then  ;Next Task
            Sleep(250)
            $FrBk = 1
        ElseIf _IsPressed("05", $hDLL) Then  ;Previous Task
            Sleep(250)
            $FrBk = 0
        ElseIf _IsPressed("02", $hDLL) Then  ;Right Mouse Key
            Sleep(250)
            _Pause()  ;Pause Program
        EndIf
    WEnd
EndFunc

Func _Pause()                              ;Create window with button.  
    GUICreate("", 0, 0, 0, 0, $style)      ;Used as blocking function.            
    GUICtrlCreateButton("", 0, 0)          ;NOTE: window and button have no size?                            
                                           ;But, it works. Strange?                                             
    While 1                                
        If _IsPressed("02", $hDLL) Then    ;Continue Program
            Sleep(250)
            GUIDelete()                    ;Delete the invisible window    
            ExitLoop
        EndIf
    WEnd    
EndFunc

Func _HideShowTask($hst)
    If NOT $hst Then
        $bGcolor = $bG
        $tpValue = 255
        $wlPaper = $wP
        $windLst = "#+m"
    EndIf

    RegWrite($key1, $val1, "REG_SZ", $wlPaper)       ;Hide/Show wallpaper
    DllCall($hDLL,"int","SystemParametersInfo","int",20,"int",0,"str",$wlPaper,"int",0)
    RegWrite($key2, $val2, "REG_SZ", $bGcolor)       ;Set/Get background color   
    WinSetTrans($tBar, "", $tpValue)                 ;Hide/Show taskbar
    WinSetTrans($pMan, "", $tpValue)                 ;Hide/Show desktop icons
    Send($windLst)                                   ;Hide/Show windows
    MouseMove($dt_W/2, $dt_H-60, 0)
EndFunc 

Func _Fade($fhand, $v1, $v2, $v3, $v4)
    For $i = $v1 To $v2 Step $v3
        WinSetTrans($fhand, "", $i)
        _Sleep($v4)
    Next
EndFunc

Func _Reset()
    FileClose($nFile)
    $nFile = FileOpen($nPath, 2)

    For $i = 1 To $nFold
        FileWriteLine($nFile, $iFold[$i] & ",1")        
    Next
EndFunc

Func _UpDate()
    $fRead = FileOpen($nPath)
    $wFile = FileOpen($nPath, 2)
        
    For $i = 1 To $nFold
        $rFold = StringSplit(FileReadLine($fRead), ",")
        
        If $i = $fPos Then
            FileWriteLine($wFile, $rFold[1] & "," & $fNum)
        Else
            FileWriteLine($wFile, $rFold[1] & "," & $rFold[2])        
        EndIf
    Next

    FileClose($wFile)
    FileClose($fRead)
EndFunc

Func _EndProgram()
    _HideShowTask(0)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    GuiDelete($iGUI)
    GUIDelete($gHWnd)                        
    FileClose($nFile)
    DllClose($hDLL)

    If $sOne Then
        If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
        _Fade($gHWnd, 254, 0, -2, 10)
        $nFile = FileOpen($nPath, 2)
        FileWrite($nFile, $iFold[1] & "," & $fNum)    
        FileClose($nFile)
    Else
        _WinAPI_SetSysColors($aElements, $sColors)
        GUIDelete($hGUI)
        FileDelete($tPath)
    EndIf    
    
    MouseClick("", $dt_W/2, $dt_H-60, 2)
    Exit
EndFunc

 

DisplayImages.au3

Link to comment
Share on other sites

  • Moderators

BackHomeAgain,

Be sensible - do you really think I am going to try and run your exact script? Not only do I not have the various text files you use (such as ImagePosition.txt), but you are also changing several system parameters such as colours. You provide a vanilla version of your script which does not do unwanted things to my system and I will be happy to take a look - as it is, not a chance.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

#NoTrayIcon
#include-once
#include <Misc.au3>
#include <File.au3>
#include <GDIPlus.au3>

Local $dt_W = @DesktopWidth, $dt_H = @DesktopHeight, $hDLL = "user32.dll"
Local $style = 0x80000000, $fPath, $fRead, $wFile

;Create full screen window to prevent right click desktop context menu.

Local $iGUI = GUICreate("", $dt_W+10, $dt_H+10, -1, -1, $style)
GuiSetState()
WinSetTrans($iGUI, "", 1)  ;Make window invisible.

;Get list of folder(s) plus level one sub folders.

Local $iFold = _FileListToArrayRec(@ScriptDir, "*", 2, -1, 1) 

Local $gHWnd, $gHWnd_, $iWidth_ = 0, $iHeight_ = 0, $FrBk = 1, $hImage
Local $sColors[2], $nFold = $iFold[0], $rFold, $Btn[$iFold[0]+1]
Local $ff, $CT = 0, $sOne = 0, $fPos, $fList, $nList, $LineCnt

_GDIPlus_Startup()

If $nFold = 1 Then   ;Single folder
    $sOne = 1
    $fPos = 1
    $fPath = $iFold[1]
    $fList = _FileListToArray($fPath)
    $nList = $fList[0]
Else
    ;Set GUI window height and width based on number of folders.
    
    Local $iMsg, $x, $y = 25, $iNum = $nFold, $nFac, $fPass = 0, $cInfo, $bTxt
    Local $wSize[7] = ["", "", 262, 377, 492, 607, 722] 
    Local $canBtn[7] = ["", "", 95, 150, 210, 265, 325] 
    Local $iCont[7] = ["", 25, 140, 255, 370, 485, 600]
        
    If $iNum <= 20 Then $nFac = 2
    If $iNum > 20 AND $iNum <= 40 Then $nFac = 3
    If $iNum > 40 AND $iNum <= 60 Then $nFac = 4
    If $iNum > 60 AND $iNum <= 80 Then $nFac = 5
    If $iNum > 80 Then $nFac = 6
    
    StringSplit(String($iNum/$nFac), ".")   ;Always round up number
    If NOT @error Then $iNum += 1
    Local $hSize = (($iNum/$nFac)*35)+85, $Count = 0
    
    Local $hGUI = GUICreate("", $wSize[$nFac], $hSize, -1,-1, 0x00C00000, 0x00000200)
    
    For $i = 1 To $nFold    ;Create folder buttons
        $Count += 1
        
        For $j = 1 To $nFac
            If $Count = $j Then $x = $iCont[$j]
        Next
        
        If $Count = $nFac Then $Count = 0
        If $i > $nFac AND $x = 25 Then $y += 35
        $Btn[$i] = GUICtrlCreateButton($iFold[$i], $x,  $y, 100, 25)
    Next
    
    $Btn[0] = GUICtrlCreateButton("Cancel", $canBtn[$nFac], $hSize-45, 75, 25, 0x0001)

    _SelectFolder()
    $fPath = $iFold[$fPos]
    $fList = _FileListToArray($fPath)
    
    If @error Then
        MsgBox(0,"Error","No files found in folder.")
        
        If $fPass Then
            _SelectAgain()
        Else
            _EndProgram()
        EndIf
    EndIf
    
    $nList = $fList[0]
    _CheckFolder()
    $fPass = 1
EndIf

_DisplayImage()

;====================================== FUNCTIONS =====================================

Func _SelectFolder()
    GUISetState(@SW_SHOW, $hGUI)
    
    While 1
        WinActivate($hGUI)
        ToolTip("")
        $iMsg = GUIGetMsg()
        $cInfo = GUIGetCursorInfo()
        
        If NOT @error Then
            $bTxt = GUICtrlRead($cInfo[4])        
            If StringLen($bTxt) > 18 Then ToolTip($bTxt)
        EndIf
        
        For $i = 0 To $nFold
            If $iMsg = $Btn[$i] Then
                $fPos = $i
                If $fPos > 0 Then ExitLoop 2
                _EndProgram()
            ElseIf _IsPressed("1B", $hDLL) Then
                Sleep(250)
                _EndProgram()
            EndIf
        Next
    WEnd
    
    ToolTip("")
    GUISetState(@SW_HIDE, $hGUI)
EndFunc

Func _CheckFolder()
    Global $FD = 0
    
    For $i = 1 To $nList
        $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$i])
    
        If NOT @error Then
            $FD = 1
            ExitLoop
        EndIf
    Next

    If $FD = 0 Then
        MsgBox(0,"Error","No images found in folder.")
        
        If $fPass Then
            _SelectAgain()
        Else
            _EndProgram()
        EndIf
    EndIf
EndFunc

Func _SelectAgain()
    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    If $FD Then _Fade($gHWnd, 255, 0, -2, 10)
    _SelectFolder()
    $fPath = $iFold[$fPos]
    $fList = _FileListToArray($fPath)
    $nList = $fList[0]
    _CheckFolder()    
    _DisplayImage()
EndFunc

Func _DisplayImage()
    Local $fNum = 0

    While 1
        If $FrBk Then
            If $fNum = $nList Then $fNum = 0
            $fNum += 1
        Else
            $fNum -= 1 
            If $fNum = 0 Then $fNum = $nList
        EndIf
    
        ;Display the image/picture.
    
        $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$fNum])
        If NOT @error Then _Images($hImage)
    WEnd
EndFunc

Func _Images($hImage)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)  
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage) 
 
    If $iHeight > $dt_H Then
        $ff = $iHeight/$dt_H        
        If ($iWidth/$ff) > $dt_W Then $ff = $iWidth/$dt_W
        $iWidth = $iWidth/$ff
        $iHeight = $iHeight/$ff
    Else
        $ff = $dt_H/$iHeight        
        If ($iWidth*$ff) > $dt_W Then $ff = $dt_W/$iWidth
        $iWidth = $iWidth*$ff
        $iHeight = $iHeight*$ff
    EndIf

    If $iWidth < $iWidth_ OR $iHeight < $iHeight_ Then _Fade($gHWnd_, 254, 0, -5, 10)    
    $gHWnd = GUICreate("", $iWidth, $iHeight, -1, -1, $style)
    GUISetState()
    WinSetTrans($gHWnd, "", 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($gHWnd)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)    
    _Fade($gHWnd, 0, 255, 1, 10)
    _Sleep(4000)
    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    $gHWnd_ = $gHWnd
    $iWidth_ = $iWidth 
    $iHeight_ = $iHeight
EndFunc

Func _Sleep($delay)
    Local $tDelay = TimerInit()    

    While TimerDiff($tDelay) < $delay
        If _IsPressed("01", $hDLL) OR _IsPressed("1B", $hDLL) Then
            Sleep(250)
            If $sOne Then
                _EndProgram()
            Else
                _SelectAgain()
            EndIf
        ElseIf _IsPressed("06", $hDLL) Then  ;Next Task
            Sleep(250)
            $FrBk = 1
        ElseIf _IsPressed("05", $hDLL) Then  ;Previous Task
            Sleep(250)
            $FrBk = 0
        ElseIf _IsPressed("02", $hDLL) Then  ;Right Mouse Key
            Sleep(250)
            _Pause()  ;Pause Program
        EndIf
    WEnd
EndFunc

Func _Pause()                              ;Create window with button.  
    GUICreate("", 0, 0, 0, 0, $style)      ;Used as blocking function.            
    GUICtrlCreateButton("", 0, 0)          ;NOTE: window and button have no size?                            
                                           ;But, it works. Strange?                                             
    While 1                                
        If _IsPressed("02", $hDLL) Then    ;Continue Program
            Sleep(250)
            GUIDelete()                    ;Delete the invisible window    
            ExitLoop
        EndIf
    WEnd    
EndFunc

Func _Fade($fhand, $v1, $v2, $v3, $v4)
    For $i = $v1 To $v2 Step $v3
        WinSetTrans($fhand, "", $i)
        _Sleep($v4)
    Next
EndFunc

Func _EndProgram()
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    GuiDelete($iGUI)
    GUIDelete($gHWnd)                        
    DllClose($hDLL)

    If $sOne Then
        If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
        _Fade($gHWnd, 254, 0, -2, 10)
    Else
        GUIDelete($hGUI)
    EndIf    
    
    Exit
EndFunc

Melba23,

Here's a reduced version.  I tested it with same issue using just two folders with images.  I ran one for a little while then selected the other and did the same.

Then I selected the "cancel" button.

Spoiler

 

 

Link to comment
Share on other sites

  • Moderators

BackHomeAgain,

Now my blood pressure has returned to something near normal after that farcical ending to the final F1 race, I am looking into the problem.

M23

Edit: You have a major problem with recursion in that script. I suggest reading the Recursion tutorial in the Wiki if you are unsure about why that is a problem. Basically you are recalling the same function from within itself - which normally ends in tears - and even though you do not get into the normal recursive loop, you are sufficiently complicating the program flow that it takes time for the "Cancel" button to be actioned when you do click it after having selected a folder. I will look at how you might adjust the flow to prevent the recursion - but not before tomorrow.

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba,

I had no idea that the script was creating recursion issue.  After reading the tutorial I checked the script.  The function "_SelectAgain" kind of says it all.  It calls three other functions again each time I select a folder even the same one.  After finishing the program a few months ago, I decided it would be nice to create a GUI to select another folder without restarting the program.  It took some time to design the GUI.  I wasn't sure how to call it again for another selection.  I appreciate the help on this subject and if you see anything else in the code that would make it more efficient let me know.

Link to comment
Share on other sites

  • Developers
2 hours ago, Melba23 said:

Now my blood pressure has returned to something near normal after that farcical ending to the final F1 race........

ditto :) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Jos,

Congrats to the Netherlands on having a first F1 World Champion - but I am afraid I do not think it was the correct way to end what has been a fantastic season.

BackHomeAgain,

Here is a skeleton script so show how you might code the folder selection GUI:

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <File.au3>
#include <GDIPlus.au3>

$sRoot = @ScriptDir

While 1
    ; Get selected folder
    $sFolderPath = _SelectFolder($sRoot)
    ConsoleWrite($sFolderPath & @CRLF)

    ; Get file list
    $aFileList = _FileListToArray($sFolderPath)

    If Not @error Then
        ; Here you call functions to display the files 
        ; But ALWAYS return to this point <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    Else
        MsgBox($MB_SYSTEMMODAL, "Error", "Empty folder" & @CRLF & @CRLF & "Please choose again")
    EndIf

WEnd



Func _SelectFolder($sRoot)

    ; Get list of folders to 1 level down
    $aFolderList = _FileListToArrayRec($sRoot, "*", 2, -1, 1)

    ; Check if any folders exist
    If $aFolderList = "" Then
        Return SetError(1, 0, 0)
    EndIf

    ; Select a folder
    If $aFolderList[0] = 1 Then
        ; Return single folder
        Return $aFolderList[1]
    Else ; Multiple folders
        ; Determine GUI size
        $iHorzButtonCount = Int($aFolderList[0] / 20) + 2                ; Suitable number of buttons horizontally
        $iGUI_W = ($iHorzButtonCount * 110) + 10
        $iVertButtonCount = Ceiling($aFolderList[0] / $iHorzButtonCount) ; Number of rows required
        $iGUI_H = ($iVertButtonCount * 35) + 10 + 35

        ; Create GUI
        $hGUI = GUICreate("", $iGUI_W, $iGUI_H) ;, -1,-1, 0x00C00000, 0x00000200)

        ; Create buttons
        Local $aButtonCID[$aFolderList[0] + 1]
        $iCount = 0
        ; Use algorithm to draw buttons
        For $i = 1 To $iVertButtonCount
            For $j = 1 To $iHorzButtonCount
                $iCount += 1
                If $iCount > $aFolderList[0] Then
                    ; No more folders to use
                    ExitLoop 2
                EndIf
                ;                                                                  (Column * (Width + Margin)) + Margin
                $aButtonCID[$iCount] = GUICtrlCreateButton($aFolderList[$iCount], (($j - 1) * 110) + 10,                (($i - 1) * 35) + 10, 100, 25)
                ;                                                                                                        (Row * (Height + Margin)) + Margin
            Next
        Next
        ; Size and place Cancel button
        $aButtonCID[0] = GUICtrlCreateButton("Cancel", 10, $iGUI_H - 35, $iGUI_W - 20, 25)

        GUISetState(@SW_SHOW)

    EndIf

    While 1

        $iMsg = GUIGetMsg()
        Switch $iMsg
            Case $GUI_EVENT_CLOSE, $aButtonCID[0]
                Exit
            Case Else
                For $i = 1 To $aFolderList[0]
                    If $iMsg = $aButtonCID[$i] Then
                        ; Clean up
                        GUIDelete($hGUI)
                        ; Return chosen folder
                        Return $aFolderList[$i]
                    EndIf
                Next
        EndSwitch
    WEnd

EndFunc

I hope it is useful. Please come back if you still have any problems getting the rest of your script to work.

M23

Edited by Melba23
Left some debugging code in the script

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

BackHomeAgain,

Be my guest. Keep safe out there.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba23, 

Still here.  I have the main functions up and running and works fine up to the point of returning to the while loop.  How do I do that?

While 1    
    Local $fPath = _SelectFolder($sRoot)     ;Get selected folder
    Local $fList = _FileListToArray($fPath)  ;Get file list

    If Not @error Then
        _HideShowTask(1)
        _DisplayImage()
    Else
        MsgBox(0, "Error", "Empty folder" & @CRLF & @CRLF & "Select again")
    EndIf
WEnd

;====================================== FUNCTIONS =====================================

Func _SelectFolder($sRoot)
    $nPath = $sRoot & "\" & "ImagePosition.txt"
    $nFile = FileOpen($nPath)
    
    ;Get list of folders to 1 level down.
    Global $iFold = _FileListToArrayRec($sRoot, "*", 2, -1, 1)

    If $iFold = "" Then
        MsgBox(0,"Error","No folders exist")
        Exit
    EndIf

;    _CheckFileList()
    $nFold =  $iFold[0]
    
    If $nFold = 1 Then   ;Return single folder
        Return $iFold[1]
    Else        
        ;Set GUI window height and width based on number of folders.
        Local $iHorzButtonCount = Int($nFold / 20) + 2
        Local $iGUI_W = ($iHorzButtonCount * 110) + 30
        Local $iVertButtonCount = Ceiling($nFold / $iHorzButtonCount)
        Local $iGUI_H = ($iVertButtonCount * 35) + 75
        
        If $iGUI_H >= $dt_H Then 
            MsgBox(0,"Error","GUI Window too large for screen.")
            Exit
        EndIf

        Global $hGUI = GUICreate("", $iGUI_W, $iGUI_H, -1, -1, 0x00C00000, 0x00000200)
        Local $Btn[$nFold + 1]
        Local $iCount = 0
    
        For $i = 1 To $iVertButtonCount
            For $j = 1 To $iHorzButtonCount
                $iCount += 1
                If $iCount > $nFold Then ExitLoop 2
                $Btn[$iCount] = GUICtrlCreateButton($iFold[$iCount], (($j - 1) * 110) + 20, (($i - 1) * 35) + 20, 100, 25)
            Next
        Next
    
        $Btn[0] = GUICtrlCreateButton("Cancel", $iGUI_W/2 - 50, $iGUI_H - 45, 100, 25)
        GUISetState(@SW_SHOW)
        
        ;Set title bar color
        $sColors[0] = _WinAPI_GetSysColor($aElements[0])
        $sColors[1] = _WinAPI_GetSysColor($aElements[1])
        DllCall("UxTheme.dll", "int", "SetWindowTheme","hwnd",$hGUI,"wstr",0,"wstr",0)
        _WinAPI_SetSysColors($aElements, $aColors)
    EndIf

    While 1
        WinActivate($hGUI)
        ToolTip("")
        $iMsg = GUIGetMsg()
        $cInfo = GUIGetCursorInfo()
        
        If NOT @error Then
            $bText = GUICtrlRead($cInfo[4])        
            If StringLen($bText) > 18 Then ToolTip($bText)
        EndIf
        
        For $i = 0 To $nFold
            If $iMsg = $Btn[$i] Then
                $fPos = $i
                If $fPos > 0 Then            
;                    _HideShowTask(0)
                    _WinAPI_SetSysColors($aElements, $sColors)
                    GUIDelete($hGUI)                    
                    Return $iFold[$fPos]
                Else
                    _EndProgram()
                EndIf
            ElseIf _IsPressed("1B", $hDLL) Then
                Sleep(250)
                _EndProgram()
            EndIf
        Next
    WEnd
EndFunc

Func _DisplayImage()
    $nList = $fList[0]
    $rFold = StringSplit(FileReadLine(FileOpen($nPath), $fPos), ",")
    Global $fNum = $rFold[2] -1
    If $fNum < 0 OR $fNum > $nList Then $fNum = 0

    While 1
        If $FrBk Then
            If $fNum = $nList Then $fNum = 0
            $fNum += 1
        Else
            $fNum -= 1 
            If $fNum = 0 Then $fNum = $nList
        EndIf
    
        ;Display the image/picture.
        $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$fNum])
        If NOT @error Then _Images($hImage)
    WEnd
EndFunc

Func _Images($hImage)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)  
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage) 
 
    If $iHeight > $dt_H Then
        $ff = $iHeight/$dt_H        
        If ($iWidth/$ff) > $dt_W Then $ff = $iWidth/$dt_W
        $iWidth = $iWidth/$ff
        $iHeight = $iHeight/$ff
    Else
        $ff = $dt_H/$iHeight        
        If ($iWidth*$ff) > $dt_W Then $ff = $dt_W/$iWidth
        $iWidth = $iWidth*$ff
        $iHeight = $iHeight*$ff
    EndIf

    ;Create window as place holder for the image/picture.
    
    If $iWidth < $iWidth_ OR $iHeight < $iHeight_ Then _Fade($gHWnd_, 254, 0, -5, 10)    
    $gHWnd = GUICreate("", $iWidth, $iHeight, -1, -1, $style)
    GUISetState()
    WinSetTrans($gHWnd, "", 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($gHWnd)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)    
    _Fade($gHWnd, 0, 255, 1, 10)
    _Sleep(4000)
    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    $gHWnd_ = $gHWnd
    $iWidth_ = $iWidth 
    $iHeight_ = $iHeight
EndFunc

Func _Sleep($delay)
    Local $tDelay = TimerInit()    

    While TimerDiff($tDelay) < $delay
        If _IsPressed("01", $hDLL) OR _IsPressed("1B", $hDLL) Then
            Sleep(250)
            _UpDate()
;Something here???
        ElseIf _IsPressed("06", $hDLL) Then  ;Next Task
            Sleep(250)
            $FrBk = 1
        ElseIf _IsPressed("05", $hDLL) Then  ;Previous Task
            Sleep(250)
            $FrBk = 0
        ElseIf _IsPressed("02", $hDLL) Then  ;Right Mouse Key
            Sleep(250)
            _Pause()  ;Pause Program
        EndIf
    WEnd
EndFunc

 

Link to comment
Share on other sites

  • Moderators

BackHomeAgain,

Once again you post an incomplete script which contains system-altering code - continue doing this and you will certainly get no more help from me.

However, I think I have managed to wrestle your script into some form of sense - although I have had to comment out huge swathes of it as I could not make them work without expending even more effort adding Global variables or files various. You will see that I have added lots of Consolewrite statements to show you how the script is progressing and that it returns to the selection GUI quite nicely:

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <File.au3>
#include <GDIPlus.au3>

$sRoot = @ScriptDir
$nPath = $sRoot & "\" & "ImagePosition.txt"
Global $fList
Global $dt_H = @DesktopHeight
Global $hDLL = DllOpen("user32.dll")

While 1
    Local $fPath = _SelectFolder($sRoot)     ;Get selected folder
    $fList = _FileListToArray($fPath)  ;Get file list

    If Not @error Then
        ;_HideShowTask(1)
        _DisplayImage()
    Else
        MsgBox(0, "Error", "Empty folder" & @CRLF & @CRLF & "Select again")
    EndIf
WEnd

;====================================== FUNCTIONS =====================================

Func _SelectFolder($sRoot)

    ConsoleWrite("In - SelectFolder" & @CRLF)

    ; $nFile = FileOpen($nPath) ; You never close this which will cause a crash eventually

    ;Get list of folders to 1 level down.
    Global $iFold = _FileListToArrayRec($sRoot, "*", 2, -1, 1)

    If $iFold = "" Then
        MsgBox(0, "Error", "No folders exist")
        Exit
    EndIf

    ;    _CheckFileList()
    $nFold = $iFold[0]

    If $nFold = 1 Then   ;Return single folder
        Return $iFold[1]
    Else
        ;Set GUI window height and width based on number of folders.
        Local $iHorzButtonCount = Int($nFold / 20) + 2
        Local $iGUI_W = ($iHorzButtonCount * 110) + 30
        Local $iVertButtonCount = Ceiling($nFold / $iHorzButtonCount)
        Local $iGUI_H = ($iVertButtonCount * 35) + 75

        If $iGUI_H >= $dt_H Then
            MsgBox(0, "Error", "GUI Window too large for screen.")
            Exit
        EndIf

        Global $hGUI = GUICreate("", $iGUI_W, $iGUI_H, -1, -1, 0x00C00000, 0x00000200)
        Local $Btn[$nFold + 1]
        Local $iCount = 0

        For $i = 1 To $iVertButtonCount
            For $j = 1 To $iHorzButtonCount
                $iCount += 1
                If $iCount > $nFold Then ExitLoop 2
                $Btn[$iCount] = GUICtrlCreateButton($iFold[$iCount], (($j - 1) * 110) + 20, (($i - 1) * 35) + 20, 100, 25)
            Next
        Next

        $Btn[0] = GUICtrlCreateButton("Cancel", $iGUI_W / 2 - 50, $iGUI_H - 45, 100, 25)
        GUISetState(@SW_SHOW)

        ;Set title bar color
        ;$sColors[0] = _WinAPI_GetSysColor($aElements[0])
        ;$sColors[1] = _WinAPI_GetSysColor($aElements[1])
        ;DllCall("UxTheme.dll", "int", "SetWindowTheme","hwnd",$hGUI,"wstr",0,"wstr",0)
        ;_WinAPI_SetSysColors($aElements, $aColors)
    EndIf

    While 1
        WinActivate($hGUI)
        ;ToolTip("")
        $iMsg = GUIGetMsg()
        ;$cInfo = GUIGetCursorInfo()

        ;If Not @error Then
        ;   $bText = GUICtrlRead($cInfo[4])
        ;   If StringLen($bText) > 18 Then ToolTip($bText)
        ;EndIf

        If $iMsg = $Btn[0] Or _IsPressed("1B", $hDLL) Then
            Sleep(250)

            ConsoleWrite("Ending" & @CRLF)


            _EndProgram()
        Else
            For $i = 1 To $nFold
                If $iMsg = $Btn[$i] Then
                    GUIDelete($hGUI)

                    ConsoleWrite("Out - Select Folder" & @CRLF)


                    Return $iFold[$i]
                EndIf
            Next
        EndIf
    WEnd
EndFunc   ;==>_SelectFolder

Func _EndProgram()

    #cs
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    GuiDelete($iGUI)
    GUIDelete($gHWnd)
    DllClose($hDLL)

    If $sOne Then
        If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
        _Fade($gHWnd, 254, 0, -2, 10)
    Else
        GUIDelete($hGUI)
    EndIf
    #ce

    Exit
EndFunc

Func _DisplayImage()

    ConsoleWrite("In - DisplayImage" & @CRLF)

    #cs
    $nList = $fList[0]
    $rFold = StringSplit(FileReadLine(FileOpen($nPath), $fPos), ",")
    Global $fNum = $rFold[2] - 1
    If $fNum < 0 Or $fNum > $nList Then $fNum = 0
    #ce
    While 1
        #cs
        If $FrBk Then
            If $fNum = $nList Then $fNum = 0
            $fNum += 1
        Else
            $fNum -= 1
            If $fNum = 0 Then $fNum = $nList
        EndIf

        ;Display the image/picture.
        $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$fNum])
        If Not @error Then
        #ce
            ;See what value is returned from the function below
            $iState = _Images(1) ;hImage)
            If $iState = 1 Then
                ; New folder wanted or exiting

                ConsoleWrite("Out - DisplayImage" & @CRLF)


                Return ; So back we go
            EndIf
        #cs
        EndIf
        #ce
    WEnd
EndFunc   ;==>_DisplayImage

Func _Images($hImage)

    ConsoleWrite("In - Images" & @CRLF)

    #cs

    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage)

    If $iHeight > $dt_H Then
        $ff = $iHeight / $dt_H
        If ($iWidth / $ff) > $dt_W Then $ff = $iWidth / $dt_W
        $iWidth = $iWidth / $ff
        $iHeight = $iHeight / $ff
    Else
        $ff = $dt_H / $iHeight
        If ($iWidth * $ff) > $dt_W Then $ff = $dt_W / $iWidth
        $iWidth = $iWidth * $ff
        $iHeight = $iHeight * $ff
    EndIf

    ;Create window as place holder for the image/picture.

    If $iWidth < $iWidth_ Or $iHeight < $iHeight_ Then _Fade($gHWnd_, 254, 0, -5, 10)
    $gHWnd = GUICreate("", $iWidth, $iHeight, -1, -1, $style)
    GUISetState()
    WinSetTrans($gHWnd, "", 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($gHWnd)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)
    _Fade($gHWnd, 0, 255, 1, 10)

    #ce

    ; Wait until the timer ends or there is a "New Folder" or Exit command
    Local $iState = _Sleep(4000)

    #cs

    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    $gHWnd_ = $gHWnd
    $iWidth_ = $iWidth
    $iHeight_ = $iHeight

    #ce

    ConsoleWrite("Out - Images" & @CRLF)


    ; Tell the function above what to do next
    Return $iState

EndFunc   ;==>_Images

Func _Sleep($delay)

    ConsoleWrite("In - Sleep" & @CRLF)


    Local $tDelay = TimerInit()

    While TimerDiff($tDelay) < $delay
        If _IsPressed("01", $hDLL) Or _IsPressed("1B", $hDLL) Then ; Left mouse / Escape
            Sleep(250)
            ;_UpDate()

            ConsoleWrite("New Folder - Sleep" & @CRLF)

            ; I am assuming this this is the bottom of the function chain
            ; So return a suitable flag value to show we are going back to choose a new folder or exit
            Return 1
        ElseIf _IsPressed("06", $hDLL) Then  ;Next Task
            Sleep(250)
            $FrBk = 1

            ConsoleWrite("Next - Sleep" & @CRLF)


            ExitLoop ; No need for a special return value as you are changing a Global variable
        ElseIf _IsPressed("05", $hDLL) Then  ;Previous Task
            Sleep(250)
            $FrBk = 0

            ConsoleWrite("Prev - Sleep" & @CRLF)


            ExitLoop ; See above
        ElseIf _IsPressed("02", $hDLL) Then  ;Right Mouse Key
            ;Sleep(250) ; Why ? < <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

            ConsoleWrite("Paused" & @CRLF)


            Do
                Sleep(10) ; Sleep is needed here to prevent the CPU from frying! <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            Until Not _IsPressed("02", $hDLL)
            ; No need to return from here as the function continues to run

            ConsoleWrite("Not Paused" & @CRLF)


        EndIf
    WEnd


    ConsoleWrite("TimeOut - Sleep" & @CRLF)

    ; But we do return from here as the timer has run down
    Return 0

EndFunc   ;==>_Sleep

Func _UpDate()

    #cs
    $fRead = FileOpen($nPath)
    $wFile = FileOpen($nPath, 2)

    For $i = 1 To $nFold
        $rFold = StringSplit(FileReadLine($fRead), ",")

        If $i = $fPos Then
            FileWriteLine($wFile, $rFold[1] & "," & $fNum)
        Else
            FileWriteLine($wFile, $rFold[1] & "," & $rFold[2])
        EndIf
    Next

    FileClose($wFile)
    FileClose($fRead)

    #ce
EndFunc

Func _Fade($fhand, $v1, $v2, $v3, $v4)
    For $i = $v1 To $v2 Step $v3
        WinSetTrans($fhand, "", $i)
        _Sleep($v4)
    Next
EndFunc

As I said above, if you want any more help then please post runnable, non-system-modifying code.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 3 weeks later...

Melba23,

I finally completed the work, and the program is running great.  I used your suggestions with no more recursion.  But there still is the issue of delay time when selecting the "Cancel" button.  See my first post.  My minimum test is two folders.  One with different size images and the other with same size.  The delay period varies.  There is no pattern when the delay will occur.  Running the program to display a couple dozen images, seems to increase the chance of "Cancel" button delay.  Occasionally selecting the folder buttons will cause delay.  I have provided a stripped-down version of the code with no system changes and no error checking.  Sorry about the confusion on my part before.

I appreciate you help plus some coding tricks.  At this stage of coding, I know enough to be dangerous.

#NoTrayIcon
#include-once
#include <Misc.au3>
#include <File.au3>
#include <GDIPlus.au3>

Global $dt_W = @DesktopWidth, $dt_H = @DesktopHeight, $sRoot = @ScriptDir
Global $gHWnd, $gHWnd_, $iWidth_ = 0, $iHeight_ = 0, $FrBk = 1, $ff 
Global $hDLL = "user32.dll", $fNum = 0, $hImage, $hGUI, $iCnt

_GDIPlus_Startup()

While 1
    Global $fPath = _SelectFolder($sRoot)     ;Get selected folder
    Global $fList = _FileListToArray($fPath)  ;Get folder file list
    Global $nList = $fList[0]
    _DisplayImage()
WEnd

;====================================== FUNCTIONS =====================================

Func _SelectFolder($sRoot)
    ;Get list of folders to 1 level down.
    Global $iFold = _FileListToArrayRec($sRoot, "*", 2, -1, 1)
    Global $nFold = $iFold[0]
    
    If $nFold = 1 Then   ;Return single folder
        Return $iFold[1]
    Else        
        ;Set GUI window height and width based on number of folders.
        Local $iHorzButtonCount = Int($nFold / 15) + 2
        Local $iGUI_W = ($iHorzButtonCount * 110) + 30
        Local $iVertButtonCount = Ceiling($nFold / $iHorzButtonCount)
        Local $iGUI_H = ($iVertButtonCount * 35) + 75
        
        $hGUI = GUICreate("", $iGUI_W, $iGUI_H, -1, -1, 0x00C00000, 0x00000200)
        Local $Btn[$nFold + 1]
        $iCnt = 0
    
        For $i = 1 To $iVertButtonCount
            For $j = 1 To $iHorzButtonCount
                $iCnt += 1
                If $iCnt > $nFold Then ExitLoop 2
                $Btn[$iCnt] = GUICtrlCreateButton($iFold[$iCnt], _
                (($j -1) *110) +20, (($i -1) *35) +20, 100, 25)
            Next
        Next
    
        $Btn[0] = GUICtrlCreateButton("Cancel", $iGUI_W/2 -50, $iGUI_H -45, 100, 25)
        GUISetState(@SW_SHOW)
    EndIf

    While 1
        WinActivate($hGUI)
        Local $iMsg = GUIGetMsg()
        
        If $iMsg = $Btn[0] OR _IsPressed("1B", $hDLL) Then
            Sleep(250)
            _EndProgram()
        Else        
            For $i = 1 To $nFold
                If $iMsg = $Btn[$i] Then
                    GUIDelete($hGUI)                    
                    Return $iFold[$i]
                EndIf
            Next
        EndIf
    WEnd
EndFunc   ;==>_SelectFolder

Func _DisplayImage()
    While 1
        If $FrBk Then
            If $fNum = $nList Then $fNum = 0
            $fNum += 1
        Else
            $fNum -= 1 
            If $fNum = 0 Then $fNum = $nList
        EndIf
    
        ;Display the image/picture.
        $hImage = _GDIPlus_ImageLoadFromFile($fPath & "\" & $fList[$fNum])
        
        If NOT @error Then
            Local $iState = _Images($hImage)
            If $iState = 1 Then Return
        EndIf        
    WEnd
EndFunc    ;==>_DisplayImage

Func _Images($hImage)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage)  
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage) 
 
    If $iHeight > $dt_H Then
        $ff = $iHeight/$dt_H        
        If ($iWidth/$ff) > $dt_W Then $ff = $iWidth/$dt_W
        $iWidth = $iWidth/$ff
        $iHeight = $iHeight/$ff
    Else
        $ff = $dt_H/$iHeight        
        If ($iWidth*$ff) > $dt_W Then $ff = $dt_W/$iWidth
        $iWidth = $iWidth*$ff
        $iHeight = $iHeight*$ff
    EndIf

    If $iWidth < $iWidth_ OR $iHeight < $iHeight_ Then _Fade($gHWnd_, 255, 0, -5, 10)
    $gHWnd = GUICreate("", $iWidth, $iHeight, -1, -1, 0x80000000)
    GUISetState()
    WinSetTrans($gHWnd, "", 0)
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND($gHWnd)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)    
    _GDIPlus_ImageDispose($hImage)
    _Fade($gHWnd, 0, 255, 1, 10)
    $iState = _Sleep(4000)
    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    $gHWnd_ = $gHWnd
    $iWidth_ = $iWidth 
    $iHeight_ = $iHeight
    Return $iState
EndFunc            ;==>_Images

Func _Sleep($delay)
    Local $tDelay = TimerInit()    

    While TimerDiff($tDelay) < $delay
        If _IsPressed("01", $hDLL) OR _IsPressed("1B", $hDLL) Then
            Sleep(250)
            GUIDelete($gHWnd_)
            _Fade($gHWnd, 255, 0, -2, 10)
            GUIDelete($gHWnd)
            If $nFold = 1 Then _EndProgram()
            Return 1
        ElseIf _IsPressed("06", $hDLL) Then  ;Next Task
            Sleep(250)
            $FrBk = 1
            ExitLoop
        ElseIf _IsPressed("05", $hDLL) Then  ;Previous Task
            Sleep(250)
            $FrBk = 0
            ExitLoop
        ElseIf _IsPressed("02", $hDLL) Then  ;Pause program
            Sleep(250)
            While 1                                
                If _IsPressed("02", $hDLL) Then  ;Continue program
                    Sleep(250)
                    ExitLoop
                EndIf
                Sleep(10)
            WEnd    
        EndIf
    WEnd
    Return 0
EndFunc

Func _Fade($fhand, $v1, $v2, $v3, $v4)
    For $i = $v1 To $v2 Step $v3
        WinSetTrans($fhand, "", $i)
        _Sleep($v4)
    Next
EndFunc

Func _EndProgram()
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    GUIDelete($gHWnd)                        
    DllClose($hDLL)
    Exit
EndFunc

 

Link to comment
Share on other sites

I'm new here, but. Why don't you try, in line #54, to take "winactivate" out of the loop? If your intention is to keep it always visible you could use $WS_EX_TOPMOST as the extended window style. I mean, for your cancel delay problem.

from:

While 1
        WinActivate($hGUI)
        Local $iMsg = GUIGetMsg()

to

WinActivate($hGUI)
    While 1        
        Local $iMsg = GUIGetMsg()

 

Edited by zid
Link to comment
Share on other sites

  • Moderators

BackHomeAgain,

I think zid has it above - removing WinActivate from the loop seems to solve the problem when I run the code. Well done zid!!

You also need to add a couple of lines to your _Images function after returning from the Sleep call:

_GDIPlus_ImageDispose($hGraphic) ; Delete the graphic <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUIDelete($gHWnd) ; Delete the current image GUI <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Otherwise you are just eating system resources and will in the end run out of them with disastrous results!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

zid,

The simplest things.  Thanks.

M23,

Put in the two lines of code.  I realize you met  GraplicsDispose.   I have a folder with over 3300 nature images downloaded from wallpaper sites.  Takes over 6 hours to run before starting over.  It performed perfectly with no issues.  Thanks again for the help.

BackHomeAgain

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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