Maffe811 Posted July 28, 2013 Share Posted July 28, 2013 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 ? expandcollapse popup#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] Link to comment Share on other sites More sharing options...
mikell Posted July 28, 2013 Share Posted July 28, 2013 (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 expandcollapse popup#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 July 28, 2013 by mikell Link to comment Share on other sites More sharing options...
Maffe811 Posted July 28, 2013 Author Share Posted July 28, 2013 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] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 28, 2013 Moderators Share Posted July 28, 2013 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: expandcollapse popup#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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted July 28, 2013 Share Posted July 28, 2013 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 28, 2013 Moderators Share Posted July 28, 2013 mikell, your script looks a bit like mineAll my own work I assure you! M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted July 28, 2013 Share Posted July 28, 2013 Hmm, History is full of events like this, appearing in the same time in different places: discovery of fire, invention of the wheel, etc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 28, 2013 Moderators Share Posted July 28, 2013 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
mikell Posted July 28, 2013 Share Posted July 28, 2013 (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 July 28, 2013 by mikell Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now