Jump to content

Recommended Posts

Posted (edited)

hello,

 

i have a question and for that i wrote two quick examples. both should work, but the one with the buttons does not, whilst the one with the radiodots does.

prog with buttons:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $buttontest = GUICreate("buttontest", 288, 61, -1, -1)
Global $start = GUICtrlCreateButton("start", 8, 16, 75, 25)
Global $stop = GUICtrlCreateButton("stop", 104, 16, 75, 25)
Global $exit = GUICtrlCreateButton("exit", 200, 16, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $exit
            Exit

        Case $start
                For $x = 1 To 100000
                    MouseMove(927, 535)
                    If GUICtrlRead($stop) = 1 Then ExitLoop
                    Sleep(2000)
                    MouseMove(927, 545)
                    If GUICtrlRead($stop) = 1 Then ExitLoop
                    Sleep(2000)
                    MouseMove(927, 555)
                    If GUICtrlRead($stop) = 1 Then ExitLoop
                    Sleep(2000)
                Next


        Case $stop
        $stop = 1
        MsgBox(0,"STOP...","the function has stopped!")

    EndSwitch
WEnd

prog with radio-dots:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $buttontest = GUICreate("buttontest", 288, 61, -1, -1)
Global $exit = GUICtrlCreateButton("exit", 200, 16, 75, 25)
Global $start = GUICtrlCreateRadio("start", 8, 24, 80, 17)
Global $stop = GUICtrlCreateRadio("stop", 96, 24, 80, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $exit
            Exit

        Case $start
            If GUICtrlRead($start) = 1 Then
                For $x = 1 To 100000
                    MouseMove(927, 535)
                    If GUICtrlRead($stop) = 1 Then ExitLoop
                    Sleep(2000)
                    MouseMove(927, 545)
                    If GUICtrlRead($stop) = 1 Then ExitLoop
                    Sleep(2000)
                    MouseMove(927, 555)
                    If GUICtrlRead($stop) = 1 Then ExitLoop
                    Sleep(2000)
                Next
                EndIf

        Case $stop
            MsgBox(0,"STOP...","the function has stopped!")


    EndSwitch
WEnd

please someone explain to me, why i can get the for loop to be stopped when i press the radio-dot but it will not work when i press a button?

going through the helpfiles i gather it has something to do with that the radio-dot returns a value and the button does not, right? 

is there a SHORT workarround for that buttons can give values back so the for loop can determine if the criteria has been met?  i mean it is okay to do it with radio-dots but from a design point of view three buttons look nicer than two radio-dots and a button.

kind regards

Edited by roeselpi
corrected minor mistake in the code
Posted

Its because GuiCtrlRead is not returning what you expect, the button is returning the word "start".  What you could do is use another variable for example" $iStart in example below:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $iStart
Global $buttontest = GUICreate("buttontest", 288, 61, -1, -1)
Global $start = GUICtrlCreateButton("start", 8, 16, 75, 25)
Global $stop = GUICtrlCreateButton("stop", 104, 16, 75, 25)
Global $exit = GUICtrlCreateButton("exit", 200, 16, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $exit
            Exit

        Case $start
            $iStart = 1
                For $x = 1 To 100000
                    MouseMove(927, 535)
                    If GUICtrlRead($stop) = 0 Then ExitLoop
                    Sleep(2000)
                    MouseMove(927, 545)
                    If GUICtrlRead($stop) = 0 Then ExitLoop
                    Sleep(2000)
                    MouseMove(927, 555)
                    If GUICtrlRead($stop) = 0 Then ExitLoop
                    Sleep(2000)
                Next


        Case $stop
        $iStart = 0
        MsgBox(0,"STOP...","the function has stopped!")

    EndSwitch
WEnd

 

Posted

hi, your example only does the first movement and then terminates. i even tried changing the GUICtrlRead($stop) = 0 to GUICtrlRead($istart) = 0 and also tried the same two possibilities with = 1 at the end. still no luck. either it runs forever or it only makes the first move and then terminates.

that would not really be the solution here. 

however i did just find something interesting out: the start button returns the value "3" and the stop button the value "4" which happens to be the third and fourth item in the koda gui section. but even that won't help. GUICtrlRead($stop) = 4 will also not terminate the loop.

any other ideas?

Posted

Sorry I missed your other GuiCtrlRead instances, if you use $start or $stop it's returning the control id,  You would actually have issues using the method you have written, because items in a loop will stop you from being able to click stop or exit, the reason it works for your radio example is that radios return an integer, i.e. $GUI_CHECKED = 1 or $GUI_UNCHECKED = 4.  If you want to use a loop use adlibregister within the gui like in the example below.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $iStart = 0 ;~ Mouse Movement is idle
Global $buttontest = GUICreate("buttontest", 288, 61, -1, -1)
Global $start = GUICtrlCreateButton("start", 8, 16, 75, 25)
Global $stop = GUICtrlCreateButton("stop", 104, 16, 75, 25)
Global $exit = GUICtrlCreateButton("exit", 200, 16, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
AdlibRegister("_ButtonTest")
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $exit
            Exit
        Case $start
            $iStart = 1
        Case $stop
        $iStart = -1
    EndSwitch
WEnd

Func _ButtonTest()
    Switch $iStart
        Case -1 ;~ Stopped Click
            MouseMove(927, 545)
                Sleep(2000)
            MouseMove(927, 555)
            MsgBox(0,"STOP...","the function has stopped!")
            $iStart = 0 ;~ Reset to idle to allow mouse movement
        Case 1
            MouseMove(927, 535) ;~ Moved over Stop Button
    EndSwitch
EndFunc

 

Posted

Here is how I would do it, only one way that this cat can be skinned.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $buttontest = GUICreate("buttontest", 288, 61, -1, -1)
Global $start = GUICtrlCreateButton("start", 8, 16, 75, 25)
Global $stop = GUICtrlCreateButton("stop", 104, 16, 75, 25)
Global $exit = GUICtrlCreateButton("exit", 200, 16, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
     $nMsg = GUIGetMsg()
     Switch $nMsg
          Case $GUI_EVENT_CLOSE
               Exit
          Case $exit
               Exit
          Case $start
               For $x = 1 To 100000
                    $nMsg = GUIGetMsg()
                    MouseMove(927, 535)
                    If $nMsg = $stop Then ExitLoop
                    $quit = Pause()
                    If $quit Then ExitLoop
                    MouseMove(927, 545)
                    If $nMsg = $stop Then ExitLoop
                    $quit = Pause()
                    If $quit Then ExitLoop
                    MouseMove(927, 555)
                    If $nMsg = $stop Then ExitLoop
                    $quit = Pause()
                    If $quit Then ExitLoop
               Next
               If $x < 10000 Then ConsoleWrite("Exited loop early" & @CRLF)
          Case $stop
               $stop = 1
               MsgBox(0, "STOP...", "the function has stopped!")
     EndSwitch
WEnd
Func Pause()
     $timer = TimerInit()
     While TimerDiff($timer) < 2000
          $nMsg = GUIGetMsg()
          If $nMsg = $stop Then
               Return 1
          EndIf
     WEnd
     Return 0
EndFunc   ;==>Pause

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

thanks a lot for those replies. that was a valuable lesson for me. it will take some time to understand it, but i will now for sure look at the GUIGetMsg function more closely.

i do not quite understand why everybody seems to use functions "Func Whatever()" so much, but i guess i am still to far away from understanding that but every day i am eagerly learning something new about autoit and that is great.

kind regards 

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