Jump to content

GUIGetMsg With a Loop?


AzKay
 Share

Recommended Posts

#include <GUIConstants.au3>

#Region ### START Koda GUI section ###
$Form1 = GUICreate("AnimeGallerie", 417, 247, 203, 122)
$Group1 = GUICtrlCreateGroup("", 8, 80, 401, 161)
$Url = GUICtrlCreateInput("http://www.animegalleries.net/show.php?img=albums/Naruto/kakashi/naruto_kakashi", 24, 104, 369, 21)
$Format = GUICtrlCreateInput(".jpg", 328, 128, 65, 21)
$Start = GUICtrlCreateInput("0000", 328, 152, 65, 21)
$End = GUICtrlCreateInput("0316", 328, 176, 65, 21)
$Download = GUICtrlCreateButton("Download", 24, 200, 105, 25)
$Progress = GUICtrlCreateLabel(".../...", 328, 208, 67, 17, $SS_CENTER)
$Stop = GUICtrlCreateButton("Stop", 136, 200, 105, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 8, 8, 401, 65)
$Folder = GUICtrlCreateInput("C:\Documents and Settings\Asus\Desktop\Images\", 24, 32, 369, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Download
                $Loop = 1
        GUICtrlSetState($Download, $GUI_DISABLE)
        $oFolder = GUICtrlRead($Folder)
        $oUrl = GUICtrlRead($Url)
        $oStart = GUICtrlRead($Start)
        $oEnd = GUICtrlRead($End)
        $oFormat = GUICtrlRead($Format)
            For $i = $oStart To $oEnd
                    InetGet($oUrl & StringFormat('%04d', $i) & $oFormat, _
                        $oFolder & StringFormat('%04d', $i) & $oFormat, 1)
                    GUICtrlSetData($Progress, StringFormat('%04d', $i) & "/" & $oEnd)
                If $Loop = 0 Then ExitLoop
            Next
                
        Case $Stop
            $Loop = 0
            InetGet("abort")
            GUICtrlSetData($Progress, ".../...")
            GUICtrlSetState($Download, $GUI_ENABLE)
    EndSwitch
WEnd

First, I was using the, OnEventMode, Then I read through the help file abit, and it says, Well, according to what ive been reading, my project would be more towards using GUIGetMsg(), Ive two problems. 1) When I go into download, It goes into the For...Next loop, How would I get it to keep checking for button input. 2) Well, That was the only question. I think.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Oh, and the second question was,

How would I make it lag less? Asin, When you click "Download" it lags alot, seeing as, its not checking as fast.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

@first problem:

You could divide it into 2 programs, 1 with the gui and the other one to download. So the first one could work (receives messages), while you are downloading. And you could also download more than one file at the same time.

Multithreading could also work i think, but i don't know much about it, i just remember a topic in this forum, with a multithreading solution. You would have to search it. But to divide it into two programs is surely easier^^

"It's easier to disintegrate an atom than a prejudice." (A.Einstein)---------------------------------------------------------------------------My C++ - tools:Tidy tool-->indents your c++ sourceCleanscript --> cleans autoit-code before compiling (co-author: peethebee)My tools:GUIBuilder-->build your window and get the source; german versionMy Games:OnlineGameCenter-->Online Chess and Connect4 with a rtf-chatSnake-->including a level editor to build your own levelsTetris-->the well known game, big funOther things:Tower of Hanoi-->perfect riddler with graphic output

Link to comment
Share on other sites

@first problem:

You could divide it into 2 programs, 1 with the gui and the other one to download. So the first one could work (receives messages), while you are downloading. And you could also download more than one file at the same time.

Multithreading could also work i think, but i don't know much about it, i just remember a topic in this forum, with a multithreading solution. You would have to search it. But to divide it into two programs is surely easier^^

Thanks for the idea, though, Im not really "into" quick fix's =P
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

  • Moderators

Running 400 copies of it with /AutoIt3ExecuteLine might do it :)

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Thanks for the tip :) Fixed it.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ###
$Form1 = GUICreate("AnimeGallerie", 417, 247, 203, 122)
$Group1 = GUICtrlCreateGroup("", 8, 80, 401, 161)
$Url = GUICtrlCreateInput("http://www.animegalleries.net/show.php?img=albums/Naruto/kakashi/naruto_kakashi", 24, 104, 369, 21)
$Format = GUICtrlCreateInput(".jpg", 328, 128, 65, 21)
$Start = GUICtrlCreateInput("0000", 328, 152, 65, 21)
$End = GUICtrlCreateInput("0316", 328, 176, 65, 21)
$Download = GUICtrlCreateButton("Download", 24, 200, 105, 25)
$Progress = GUICtrlCreateLabel(".../...", 328, 208, 67, 17, $SS_CENTER)
$Stop = GUICtrlCreateButton("Stop", 136, 200, 105, 25, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("", 8, 8, 401, 65)
$Folder = GUICtrlCreateInput("C:\Documents and Settings\Asus\Desktop\Images\", 24, 32, 369, 21)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Download
                $ForLoop = 1
        GUICtrlSetState($Download, $GUI_DISABLE)
        $oFolder = GUICtrlRead($Folder)
        $oUrl = GUICtrlRead($Url)
        $oStart = GUICtrlRead($Start)
        $oEnd = GUICtrlRead($End)
        $oFormat = GUICtrlRead($Format)
            DirMove($oFolder, $oFolder)
                If @Error = 0 Then DirCreate($oFolder)
            For $i = $oStart To $oEnd
                InetGet($oUrl & StringFormat('%04d', $i) & $oFormat, _
                    $oFolder & StringFormat('%04d', $i) & $oFormat, 1, 1)
                        While @InetGetActive
                            $Msg = GUIGetMsg()
                            $WhileLoop = 1
                        Switch $Msg
                            Case $Stop
                                $WhileLoop = 0
                                GUICtrlSetState($Download, $GUI_ENABLE)
                                If $WhileLoop = 0 Then
                                    $ForLoop = 0
                                    ExitLoop
                                EndIf
                        EndSwitch
                        WEnd
                    GUICtrlSetData($Progress, StringFormat('%04d', $i) & "/" & $oEnd)
                If $ForLoop = 0 Then ExitLoop
                If $i = $oEnd Then
                    GUICtrlSetState($Download, $GUI_ENABLE)
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd

EDIT::

Added in a "If not direxists then dircreate" and made it enable the download button once its downloaded.

Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
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...