Jump to content

Help with Opt("GUIOnEventMode",1)


Recommended Posts

Hello everybody I need help with Opt("GUIOnEventMode",1) 

I Normally use GUIGetMsg() but I want to learn how GUIOnEventMode works so I created a little test GUI the start button works fine and everything but the problem is that the stop button won't work down below is the code  I made and I'm wondering if someone with experience can explain me and the rest o newbies how it works and also if can post the code already fixed

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>





$Stop = False
    $X=1
$i = 0
Opt("GUIOnEventMode",1)

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 579, 212, 192, 124)
Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25)
Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25)
Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent ($GUI_EVENT_CLOSE, "_exit",$Form1 )
GUICtrlSetOnEvent($Button1,"_Stop")
GUICtrlSetOnEvent($Button2,"DecreaseAndIncrement")


While 1
    sleep(500)
WEnd



Func _Stop ()
    $Stop = True
EndFunc


Func _exit ()
    Exit
EndFunc


Func DecreaseAndIncrement ()

$Stop = False

While $Stop = False
    $i+=$X
;ConsoleWrite($i & @CRLF)

GUICtrlSetData($Progress1,$i)
Sleep(80)

if $i = 105 Then $X = -1
if $i = 0 Then $X =  1

WEnd

EndFunc

 

 

here is the version that works with GUIGetMsg()

 

 

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>





$Stop = False
    $X=1
$i = 0


#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 579, 212, 192, 124)
Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25)
Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25)
Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

        Case $Button2
            DecreaseAndIncrement ()

        case $Button1
            $Stop = True

    EndSwitch
WEnd



Func DecreaseAndIncrement ()


$Stop = False

While $Stop = False
    $i+=$X
;ConsoleWrite($i & @CRLF)

GUICtrlSetData($Progress1,$i)
Sleep(80)

if $i = 105 Then $X = -1
if $i = 0 Then $X =  1

$nMsg2 = GUIGetMsg()
Switch $nMsg2

    Case $GUI_EVENT_CLOSE
            Exit

    case $Button1
            $Stop = True


EndSwitch

WEnd

EndFunc

 

 

 

 

 

 

 

Edited by Mannyfresh31
Typo
Link to comment
Share on other sites

Once it goes into the function it's stuck inside the While/Wend loop, instead you could use something like:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode",1)

Global $Stop = True
Global $x = 1, $i = 0

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 579, 212, 192, 124)
Global $Button1 = GUICtrlCreateButton("Stop", 432, 136, 75, 25)
Global $Button2 = GUICtrlCreateButton("Start", 96, 136, 75, 25)
Global $Progress1 = GUICtrlCreateProgress(24, 40, 526, 49)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUISetOnEvent ($GUI_EVENT_CLOSE, "_exit",$Form1 )
GUICtrlSetOnEvent($Button2,"_Start")
GUICtrlSetOnEvent($Button1,"_Stop")

While 1
    While $Stop = False
        $i += $X
        GUICtrlSetData($Progress1,$i)
        Sleep(80)
        if $i = 105 Then $X = -1
        if $i = 0 Then $X =  1
    WEnd
    Sleep(80)
WEnd

Func _Stop ()
    $Stop = True
EndFunc

Func _exit ()
    Exit
EndFunc

Func _Start ()
    $Stop = False
EndFunc

 

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

×
×
  • Create New...