Jump to content

Recommended Posts

  • Moderators
Posted

BackHomeAgain,

A read of the Recursion tutorial in the Wiki might offer you some useful pointers as to what such a script might entail.

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

 

Posted

Look in " Auto GUI Help and Support" under "Main GUI window"     User BackHomeAgain

I received one replay and that was to provide some code.  Later, I provided an attachment of the complete script.

Still no more replies.  So, I decided to try a different approach.  Hope this explains.

Seems first attempt only works once.  Second attempt does not only display the GUI but a MsgBox as  well.

Multiple MsgBox same results.   Something is not allowing "windows" to be displayed.  Otherwise, code works fine in both attempts.

Posted

Jos,

Did you look at the attachment?

#RequireAdmin
#NoTrayIcon
#include-once
#include <Misc.au3>
#include <File.au3>
#include <GDIPlus.au3>
#include <WinAPI.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, $iPID
Local $bGcolor = 0x000000, $tpValue = 0, $wlPaper = "", $windLst = "#m"
Local $cCopy, $cCursor = 32512, $blkCursor, $style = 0x80000000, $fPath

;Create full screen window to prevent right mouse click desktop context menu.
Local $iGUI = GUICreate("", $dt_W+10, $dt_H+10, -1, -1, $style)
GuiSetState()
WinSetTrans($iGUI, "", 1)  ;Make window invisible.

Local $iFold = _FileListToArray(@ScriptDir, "*", 2)   ;Get folder(s)
If @error = 4 Then Exit

Local $nPath = "ImagePosition.txt", $nFile = FileOpen($nPath)
If @error = -1 Then Exit

Local $gHWnd, $gHWnd_, $iWidth_ = 0, $iHeight_ = 0, $FrBk = 1, $hImage, $CT = 0
Local $sColors[2], $nFold = $iFold[0], $rFold, $Btn[$iFold[0]+1], $ff, $SW = 1

;Check for missing folders and invalid data
Local $LineCnt = _FileCountLines($nPath)

If $LineCnt = 0 OR $nFold <> $lineCnt Then
    _Reset($nFile, $nPath, $iFold)
    $SW = 0
EndIf

If $SW Then
    For $i = 1 To $LineCnt
        $rFold = StringSplit(FileReadLine($nFile), ",")

        If @error OR Not StringIsDigit($rFold[2]) Then
            _Reset($nFile, $nPath, $iFold)            
            $SW = 0
            ExitLoop
        EndIf        
    Next
EndIf

If $SW Then
    FileClose($nFile)
    $nFile = FileOpen($nPath)
    
    For $i = 1 To $LineCnt
        $rFold = StringSplit(FileReadLine($nFile), ",")
        
        For $j = 1 To $nFold
            If StringCompare($rFold[1], $iFold[$j], 1) = 0 Then $CT += 1
        Next
    Next
    
    If $CT <> $nFold Then _Reset($nFile, $nPath, $iFold)            
EndIf

If $iFold[0] = 1 Then   ;Only one folder
    $fPath = $iFold[1]
Else
    Local $fPos, $iMsg, $x, $y = 25, $iNum = $nFold

    For $i = 1 To $iNum Step 2
        If $iNum = $i Then $iNum += 1   ;Check for odd number of folders
    Next
    
    ;Set GUI window height based on number of folders and create the window       
    Local $hSize = (($iNum/2)*30)+90
    Local $hGUI = GUICreate("", 262, $hSize, -1,-1, 0x00C00000, 0x00000200)
    
    For $i = 1 To $nFold                 ;Create folder buttons
        If Mod($i, 2) <> 0 Then $x = 25        
        If Mod($i, 2) = 0 Then $x = 140
        
        If $i > 2 Then 
            If $x = 25 Then $y += 30
        EndIf

        $Btn[$i] = GUICtrlCreateButton($iFold[$i], $x,  $y, 100, 25)
    Next
    
    $Btn[0] = GUICtrlCreateButton("Cancel", 95, $hSize-45, 75, 25, 0x0001)

    ;Setup window bar colors
    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)
    GUISetState()

    While 1                  ;Get selected folder
        WinActivate($hGUI)
        $iMsg = GUIGetMsg()
    
        For $i = 0 To $nFold
            If $iMsg = $Btn[$i] Then
                $fPos = $i
                If $fPos > 0 Then ExitLoop 2
                GUIDelete($hGUI)
                Exit
            ElseIf _IsPressed("1B", $hDLL) Then
                Sleep(250)
                GUIDelete($hGUI)
                Exit
            EndIf
        Next
    WEnd

    GUIDelete($hGUI)
    $fPath = $iFold[$fPos]
EndIf


;Get number of images from folder and current number position within the list
FileClose($nFile) 
$rFold = StringSplit(FileReadLine(FileOpen($nPath), $fPos), ",")
Local $fList = _FileListToArray($fPath)
Local $fNum = $rFold[2] -1
If $fNum < 0 OR $fNum > $fList[0] Then $fNum = 0

_HideShowTask(1)
_GDIPlus_Startup()

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

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

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)
            _EndProgram()  ;Restore, Update, Close, Delete  
        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

    Sleep(2000)
    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)
    
    If $hst Then    ;Hide/Show system pointer cursor
        $blkCursor = _WinAPI_LoadCursorFromFile("Blank_Cursor.cur")
        $cCopy = _WinAPI_CopyCursor(_WinAPI_LoadCursor(0, $cCursor))
        _WinAPI_SetSystemCursor($blkCursor, $cCursor)
    Else
        _WinAPI_SetSystemCursor($cCopy, $cCursor) 
    EndIf
EndFunc 

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

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

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

Func _EndProgram()
    If IsHWnd($gHWnd_) Then GUIDelete($gHWnd_)
    _Fade($gHWnd, 254, 0, -2, 10)
    _HideShowTask(0)
    _WinAPI_DestroyCursor($blkCursor)
    _WinAPI_SetSysColors($aElements, $sColors)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()
    GUIDelete($gHWnd)                        
    GuiDelete($iGUI)
    DllClose($hDLL)
    FileClose($nFile)
    Local $fRead = FileOpen($nPath)
    Local $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)
    ControlSend("Program Manager", "", 1, "{F5}")
    MouseClick("")
    
    MsgBox(0,"","test",2)

    If ProcessExists($iPID) Then ProcessClose($iPID)
    $iPID = Run("Display_Images.exe")
    Exit
EndFunc

 

Posted

 

Look in " Auto GUI Help and Support" under "Main GUI window" 

Create a folder.  Download the attachment and place in the folder.  Copy more the one folder with images/pictures to the the new folder.

Run the script.  Select one of the buttons. A list of pics will begin to display on the screen.  Stop the script by clicking the left mouse key.

The GUI will display again.  Select the same or another button. If you select the same button,  the last image you saw will begin where you left off from the previous selection.

Again stop the script.  This time no GUI or MsgBox which I used as a test case.  If you run the script again same issue occurs as describe above.

So, why does the GUI not appear?

Posted

Repeating endlessly will achieve no results. Ask the question differently. Present a working problem that simulates the problem. I still have no idea what you want.

 

Skysnake

Why is the snake in the sky?

Posted

What you are asking is that someone debug your script for you.  Put some cw in your script, follow its path, and you will eventually find the problem.  Nobody will do that for you, unless you create a small replicable snippet of your script that shows the problem.

  • Developers
Posted (edited)

Is it correct that your script needs to be compiled and and call it "Display_Images.exe"?
So your idea of re-showing the GUI is to end the current program and start it again with :     $iPID = Run("Display_Images.exe") ?

This part doesn't make any sense:

If ProcessExists($iPID) Then ProcessClose($iPID)
    $iPID = Run("Display_Images.exe")
    Exit

$pid is not set before and is right away lost after the run command since you exit!

... but my stab in the dark is that the workdir is changed and it cant find "Display_Images.exe" anymore....  but not going to run this.
I would start rethinking its design and avoid ending and restarting it.

Edited by Jos

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.
  :)

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
  • Recently Browsing   0 members

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