Rhyono Posted December 9, 2012 Share Posted December 9, 2012 My program spends most of its time in a function that is being looped. I am using GUISetOnEvent for exiting the program, but it appears that it only checks on that when not in the loop. Once the loop starts however, it doesn't end until it meets a user specified time, which could be hours away. What can I do so that the X button always works? Link to comment Share on other sites More sharing options...
FireFox Posted December 9, 2012 Share Posted December 9, 2012 (edited) Hi, Yes, just reset the onevent mode before entering in your loop and use the GUIGetMsg function. ... Opt("GUIOnEventMode", 0) While 1 $iMsg = GUIGetMsg() If $iMsg = $GUI_EVENT_CLOSE Then ... ... WEnd Opt("GUIOnEventMode", 1) ... Br, FireFox. Edited December 9, 2012 by FireFox Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 Doing that results in my "start" button that uses GUISetOnEvent to not work. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted December 9, 2012 Moderators Share Posted December 9, 2012 So how about posting your code so we're not left to guess? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
PhoenixXL Posted December 9, 2012 Share Posted December 9, 2012 Once the loop starts however, it doesn't end until it meets a user specified time, which could be hours awayMake the loop to be of maximum 20millisecs orelse dont use events for your GUI use msg instead, inside the loop My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Rhyono, This works for me #include <GUIConstants.au3> Opt('GUIOnEventMode', 1) local $gui010 = guicreate('') GUISetOnEvent($gui_event_close,'_exit',$gui010) GUISetState(@SW_SHOW) while 1 wend func _exit() Exit endfunc I would say that the loop is pretty tight. Is the guisetonevent after the guicreate stmt? Anything further you'll have to do as JLogan3o13 suggests. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 It's easier to just explain the code than post the whole thing: GUISetOnEvent for the close and start is here The loop is here Then the start button initiates a function that is not the loop down here, but loops every three seconds. @kylomas That works just fine, UNTIL my looping function begins. Since it never leaves the function after that (except to go to other functions), it never returns control back to the GUI in order for the event to be noticed. Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Rhyono, To get any REAL help you will need to post the code or a reproducer. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 I sort of solved it by using a check box to determine if it is time to quit by having the looping function check the value of the check box each time. Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Rhyono, Curious how/why your function is blocking the script? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 (edited) I assumed it's because my function never truly exits itself. The X button works up until I start the self-looping portion of the program. Once I'm in that loop, it never gives it a chance to check. Here's a simplified version, but with the same results: #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $Main = GUICreate("Title", 317, 207, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE,"quit") ; Enable closing $startButton = GUICtrlCreateButton("Start", 81, 160, 75, 25) GUICtrlSetOnEvent($startButton,"begin") GUISetState(@SW_SHOW) While 1 Sleep(1000) WEnd Func begin() ; Other stuff is done here in the main program, it isn't just a pointless redirect to another function main_func() EndFunc Func main_func() Sleep(3000) main_func() EndFunc Func quit() Exit EndFunc Edited December 9, 2012 by Rhyono Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Ryhono, I was hoping that it was the recursion in main_func(), however, this code has no recursion and exhibits the exact same behavior. #include <GUIConstants.au3> Opt('GUIOnEventMode', 1) local $gui010 = guicreate('') GUISetOnEvent($gui_event_close,'_exit',$gui010) local $btn010 = guictrlcreatebutton('start',0,0,100,20) guictrlsetonevent(-1,'_start') GUISetState(@SW_SHOW) while 1 wend func _start() while 1 sleep(100000) wend endfunc func _exit() Exit endfunc Maybe a gui heavy hitter will weigh in on this. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 Ryhono, Interestingly, when the func is not driven by an event it works. #include <GUIConstants.au3> Opt('GUIOnEventMode', 1) local $gui010 = guicreate('') GUISetOnEvent($gui_event_close,'_exit',$gui010) local $btn010 = guictrlcreatebutton('start',0,0,100,20) guictrlsetonevent(-1,'_start') GUISetState(@SW_SHOW) ;~ while 1 ;~ wend _start() func _start() while 1 sleep(100000) wend endfunc func _exit() Exit endfunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
PhoenixXL Posted December 9, 2012 Share Posted December 9, 2012 Autoit is Single-Threaded thats maybe the answer !! My code: PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners. MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression. Link to comment Share on other sites More sharing options...
FireFox Posted December 9, 2012 Share Posted December 9, 2012 Autoit is Single-Threaded thats maybe the answer !! It is. Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 FireFox, Please explain. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 9, 2012 Moderators Share Posted December 9, 2012 kylomas,Reading the Interrupting a running function tutorial in the Wiki might help. 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...
FireFox Posted December 9, 2012 Share Posted December 9, 2012 Reading the Interrupting a running function tutorial in the Wiki might help. This is a great example. Link to comment Share on other sites More sharing options...
kylomas Posted December 9, 2012 Share Posted December 9, 2012 M23, Thanks, it was this simple! expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $Main = GUICreate("Title", 317, 207, 192, 124) GUISetOnEvent($GUI_EVENT_CLOSE,"quit") ; Enable closing $startButton = GUICtrlCreateButton("Start", 81, 160, 75, 25) GUICtrlSetOnEvent($startButton,"begin") GUISetState(@SW_SHOW) guiregistermsg($wm_command,'_return') While 1 Sleep(1000) WEnd Func begin() ; Other stuff is done here in the main program, it isn't just a pointless redirect to another function main_func() EndFunc Func main_func() Sleep(3000) main_func() EndFunc func _return($hWnd, $Msg, $wParam, $lParam) ConsoleWrite(bitand($wparam,0x0000ffff) & @LF) if bitand($wparam,0x0000ffff) = $wm_destroy then quit() endfunc Func quit() Exit EndFunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Rhyono Posted December 9, 2012 Author Share Posted December 9, 2012 (edited) Hmmm...that exact code doesn't work for me still, kylomas. Once the start button has been pressed, you can no longer exit the program still. Edited December 9, 2012 by Rhyono 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