Jump to content
Sign in to follow this  
Mannyfresh31

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

Share this post


Link to post
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

 

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Slipk
      Hello everyone,
      I have a problem that from the title may sound a little bit confusing.
       
      I have a listview interface with a context menu and as you know it's working only if GuiOnEventMode is enabled.
      However, I need a script that can check whenever the user right click on a listview item and automatically enable GuiOnEventMode to make the function run when he click menu item.
      I have some buttons next to listview that need to work while this is possible too.
       
      It this even can be done?
      Thank you and sorry for my bad english.
    • By AndreyS
      Tell me, please, why in the application of different styles($SS_BLACKFRAME, $SS_BLACKRECT, etc.) of frames stops working function Msg().
      And why in the application of certain frame styles($SS_BLACKFRAME) do not even picture displayed?
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> Opt("GUIOnEventMode", 1) Example() Func Example() GUICreate("My GUI picture", 350, 300, -1, -1) ; will create a dialog box that when displayed is centered GUISetOnEvent($GUI_EVENT_CLOSE,"Quit") $idPic = GUICtrlCreatePic("D:\Program Files\AutoIt3\Examples\GUI\mslogo.jpg", 50, 50, 200, 50, $SS_SUNKEN) GUICtrlSetOnEvent(-1,"Msg") GUISetState(@SW_SHOW) ; Loop until the user exits. While 1 WEnd EndFunc ;==>Example Func Msg() MsgBox(0,0,0) EndFunc Func Quit() Exit EndFunc  
    • By tarretarretarre
      Inspired from

      I created a UDF that I have been using to replace GUICtrlSetOnEvent, not using Opt("GUIOnEventMode").
      AutoIt's GUICtrlSetOnEvent function only supports mouse clicks without parameters at this moment, this UDF works on the same premise but gives the user some more flexibility, in just 61 lines of code.
      Here is an example of what A callback will look like
      Func MyCallBackFunction(Const $wParam, ByRef $iCtrlId, ByRef $uData, ByRef $hWnd) Switch $wParam Case $WM_HOVERIN ConsoleWrite("Entering control; attached data = " & $uData & @CRLF) Case $WM_HOVEROUT ConsoleWrite("Leaving control" & @CRLF) Case $WM_LBUTTONDOWN ConsoleWrite("Left mousebutton DOWN" & @CRLF) Case $WM_LBUTTONUP ConsoleWrite("Left mousebutton UP" & @CRLF) Case $WM_MBUTTONDOWN ConsoleWrite("Middle mousebutton DOWN" & @CRLF) Case $WM_MBUTTONUP ConsoleWrite("Middle mousebutton UP" & @CRLF) Case $WM_RBUTTONDOWN ConsoleWrite("Right mousebutton DOWN" & @CRLF) Case $WM_RBUTTONUP ConsoleWrite("Right mousebutton UP" & @CRLF) EndSwitch EndFunc  
      More examples can be found in the zip file.
      Good 2 know
      GuiDelete($hWnd) used together with $WM_LBUTTONUP will cause the AutoIt script to crash $WM_HOVERIN and $WM_HOVEROUT ARE NOT real Windows Message codes and will only work with with this UDF Your callback functions MUST have 4 parameters assigned to it. That's about it.
      Feel free to pitch some improvements.
      /Tarre
       
      _GuiCtrlSetOnEvent.zip
    • By Leo1906
      I read about GUIOnEventMode while making my research and I found out that you can't use 
      Opt("GUIOnEventMode", 1)
      and
      $msg = GUIGetMsg()
      at the same time. So far so good.
      In my script I am spawning a few child GUIs and only for the main GUI I need interaction with buttons etc.
      My question now is, is it possible to set those flags specifically for a single GUI? Can I somehow pass the handle to a GUI this option should affect? And for the main GUI I use GuiGetMsg?
      I hope you can understand what I'm trying to do ..
       
      Thanks for your help
    • By shotiko
      here I am writing simple gui with text processing capabilities.
      i have main gui, background picture, all buttons with labels over them 2 static buttons (1 present here)
      Opt("GUIOnEventMode", 1) and includes
      $main = GUICreate("Title", 961, 721); Main Window $bgpic = GUICtrlCreatePic(@WorkingDir & "\960x720.jpg", 0, 0, 960, 720); use background picture $quitBtn = GUICtrlCreateButton("Quit", 885, 685, 95, 40) GUICtrlSetOnEvent($quitBtn, "_exit"); assign quit button to function "exit" _GuiCtrlMakeTrans(-1, 1) $quitLabel = GUICtrlCreateLabel("Quit", 885, 685, 95, 40, BitOR($SS_CENTER, $BS_BOTTOM)) GUICtrlSetFont(-1, 14, 400, 0, "Tahoma") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) GUICtrlSetColor(-1, 0x962129) GUISetState(@SW_SHOW)
      then i have the code for creating buttons dynamically from information in file
      Dim $Button[$NumberFromText] $startX = 48 $startY = 24 $fromLeft = 240 $bHeigh = 160 $bWidth = 50 Dim $1to4btn[0] For $x = 0 To _Min(UBound($Button) - 1, 3) ; creates maximum 4 button, label $Button = GUICtrlCreateButton($x, $startX, $startY, $bHeigh, $bWidth); create buttons _GuiCtrlMakeTrans(-1, 1) ; transparency 255 Solid, 0 Transparent $serverLabel = GUICtrlCreateLabel(FileReadLine($configF, $SN), _ ; read 1st line and 5 below on each iteration $startX, $startY, $bHeigh, $bWidth, BitOR($SS_CENTER, $SS_CENTERIMAGE, $WS_EX_TRANSPARENT)); GUICtrlSetFont(-1, 14, 400, 0, "Tahoma"); set font and size GUICtrlSetColor($serverLabel, 0x04A111); set color of font GUICtrlSetBkColor($serverLabel, $GUI_BKCOLOR_TRANSPARENT); make label Background transparent $SN += 5; read 5 lines below $startX = $startX + $fromLeft $btnArray=_ArrayAdd($1to4btn, GUICtrlGetHandle($Button)) Next since buttons are created under the label $Button and I couldn't conacenate $Button[$i] , I created array and place handles into it and connected static buttons with
      GUICtrlSetOnEvent($cancelBtn,"cancelFunc") and it worked
      now i tried using handles to assign functions to buttons but it fails with GUICtrlSetOnEvent()
      also tried GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "funcForFirstButton", $1to4btn[0])
      if I assign without handle it works by clicking anywhere on MainGUI
      While loop includes only sleep(10)
       
      Window starts as inactive and return code 7
      If i click dynamically created buttons, window loses focus . clicking anywhere else focuses window
       
      this is _GuiCtrlMakeTrans function (found here on forums some time ago)
      also created simple button on the same mainGUI and tried but didn't work
      $try=GUICtrlCreateButton("TRY",250,150,100,35) GUICtrlSetOnEvent(-1,"FunctionOne") ; shows messagebox and write console  
×
×
  • Create New...