Sign in to follow this  
Followers 0
Maffe811

GuiOnEventMode and multiple guis not working

9 posts in this topic

So i tried using GuiOnEventMode, but when i made the SecondGui the buttons wouldn't respond.
Is it like the functions can't be called since its in a function or am i doing something wrong ?

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

Opt("GUIOnEventMode", 1)

Global $State = 0

$Gui = GUICreate("Main gui", 150, 60)
$Button1 = GUICtrlCreateButton("Open", 10, 10, 60, 40)
$Button2 = GUICtrlCreateButton("Exit", 80, 10, 60, 40)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseMain")
GUICtrlSetOnEvent($Button1, "SecondGui")
GUICtrlSetOnEvent($Button2, "CloseMain")

Func CloseMain()
    Exit
EndFunc   ;==>CloseMain

Func CloseSecond()
    $State = 1
EndFunc   ;==>CloseSecond

Func Msg()
    MsgBox("", "", "A BOX!")
EndFunc   ;==>Msg

Func SecondGui()
    $SecondGui = GUICreate("Second gui", 150, 60)
    $ButtonMsg = GUICtrlCreateButton("Msg", 10, 10, 60, 40)
    $ButtonClose = GUICtrlCreateButton("Close", 80, 10, 60, 40)
    GUISetState(@SW_SHOW)

    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseSecond")
    GUICtrlSetOnEvent($Button1, "Msg")
    GUICtrlSetOnEvent($Button2, "CloseSecond")

    While $State = 0
        Sleep(40)
    WEnd
EndFunc   ;==>SecondGui

While 1
    Sleep(40)
WEnd

[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This wiki http://www.autoitscript.com/wiki/Interrupting_a_running_function says :

"If you are in OnEvent mode then there is an easy way to interrupt a running function, as long as the function is started within the main code and not by an OnEvent call."

That's why the while loop in SecondGui() keeps on blocking and your $State flag doesn't work

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

Opt("GUIOnEventMode", 1)

Global $SecondGui

$Gui = GUICreate("Main gui", 150, 60)
$Button1 = GUICtrlCreateButton("Open", 10, 10, 60, 40)
$Button2 = GUICtrlCreateButton("Exit", 80, 10, 60, 40)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseMain")
GUICtrlSetOnEvent($Button1, "SecondGui")
GUICtrlSetOnEvent($Button2, "CloseMain")

Func CloseMain()
    Exit
EndFunc   ;==>CloseMain

Func CloseSecond()
     GuiDelete($SecondGui)
EndFunc   ;==>CloseSecond

Func Msg()
    MsgBox("", "", "A BOX!")
EndFunc   ;==>Msg

Func SecondGui()
    $SecondGui = GUICreate("Second gui", 150, 60)
    $ButtonMsg = GUICtrlCreateButton("Msg", 10, 10, 60, 40)
    $ButtonClose = GUICtrlCreateButton("Close", 80, 10, 60, 40)
    GUISetState(@SW_SHOW)

    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseSecond")
    GUICtrlSetOnEvent($ButtonMsg, "Msg")
    GUICtrlSetOnEvent($ButtonClose, "CloseSecond")

  ;  While $State = 0
      ;  Sleep(40)
  ;  WEnd
EndFunc   ;==>SecondGui

While 1
    Sleep(40)
WEnd
Edited by mikell

Share this post


Link to post
Share on other sites

Okay, just gotta have to work with it then.

Thanks for the reply! :)


[font="helvetica, arial, sans-serif"]Hobby graphics artist, using gimp.Automating pc stuff, using AutoIt.Listening to music, using Grooveshark.[/font]Scripts:[spoiler]Simple ScreenshotSaves you alot of trouble when taking a screenshot!Don't remember what happened with this, but aperantly the exe is all i got.If you don't want to run it, simply don't._IsRun UDFIt figures out if the script has ben ran before based on the info in a ini file.If you don't want to use exactly what i wrote, you can use it as inspiration.[/spoiler]

Share this post


Link to post
Share on other sites

Maffe811,

Three things that prevent the script form working:

- 1. You are not using the correct variable names for the seconf GUI buttons when you set the events - so they do not fire.

- 2. You never actually delete the second GUI - so you never get back to the first.

- 3. As explained above, you stay in loop within a function - never a good idea inOnEvent mode. Just use the one main loop and always return to it.

So a modified script looks like this:
 

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $SecondGui ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Declare as Global

$Gui = GUICreate("Main gui", 150, 60)
$Button1 = GUICtrlCreateButton("Open", 10, 10, 60, 40)
$Button2 = GUICtrlCreateButton("Exit", 80, 10, 60, 40)
GUISetState(@SW_SHOW)

GUISetOnEvent($GUI_EVENT_CLOSE, "CloseMain")
GUICtrlSetOnEvent($Button1, "SecondGui")
GUICtrlSetOnEvent($Button2, "CloseMain")

Func CloseMain()
    Exit
EndFunc   ;==>CloseMain

Func CloseSecond()
    GUIDelete($SecondGui) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Delete the GUI
EndFunc   ;==>CloseSecond

Func Msg()
    MsgBox("", "", "A BOX!")
EndFunc   ;==>Msg

Func SecondGui()
    $SecondGui = GUICreate("Second gui", 150, 60)
    $ButtonMsg = GUICtrlCreateButton("Msg", 10, 10, 60, 40)
    $ButtonClose = GUICtrlCreateButton("Close", 80, 10, 60, 40)
    GUISetState(@SW_SHOW)

    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseSecond")
    GUICtrlSetOnEvent($ButtonMsg, "Msg") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Use correct variable name !
    GUICtrlSetOnEvent($ButtonClose, "CloseSecond") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Use correct variable name !

    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Remove loop

EndFunc   ;==>SecondGui

While 1
    Sleep(10)
WEnd

which works fine for me. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Melba,

I omitted the #1 and #2 errors because even when these corrected the code still didn't work because of the onevent thing, and forgot to mention them because solving the #3 leads naturally to find them

BTW though I'm not completely awake your script looks a bit like mine dub.gif

Share this post


Link to post
Share on other sites

mikell,

 

your script looks a bit like mine

All my own work I assure you! :D

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Hmm, History is full of events like this, appearing in the same time in different places: discovery of fire, invention of the wheel, etc :D

Share this post


Link to post
Share on other sites

mikell,

My favourite coincidence is Darwin and Wallace both arriving at the theory of evolution almost simultaneously. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

A nice example indeed, though I admit to be personally more impressed by those where it's evident that the geographic distance and cultural difference made any kind of communication impossible ;)

Edited by mikell

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  
Followers 0