Realm Posted July 13, 2010 Share Posted July 13, 2010 Working with GUIOnEventMode, While the script is looping in a function, it will not detect when/if Pause or $GUI_EVENT_CLOSE messages. I figure the Function must end for GUIOnEventMode to work. So is there a way to read the Gui message from another function and perform an OnEvent? #include <GUIConstantsEx.au3> Opt('MustDeclareVars', 1) Opt("GUIOnEventMode", 1) Local $GUI_EVENT_Run,$GUI_EVENT_Pause,$gui $gui = GUICreate("CELLUBOT INSTALLER") GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") $GUI_EVENT_Run = GUICtrlCreateButton("Run", 10, 10, 65, 20) GUICtrlSetOnEvent($GUI_EVENT_Run, "RunApplication") $GUI_EVENT_Pause = GUICtrlCreateButton("Pause", 95, 10, 65, 20) GUICtrlSetOnEvent($GUI_EVENT_Pause, "TogglePause") GUISetState(@SW_SHOW) While 1 Sleep(1000) WEnd ;This is where my script gets lost in itself, and will not detect if the Pause or Terminated buttons have been pressed. Func RunApplication() _FirstFunction() _SecondFunction() _ThirdFunction() RunApplication() EndFunc My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
MvGulik Posted July 13, 2010 Share Posted July 13, 2010 Your using GUISetOnEvent($GUI_EVENT_CLOSE, "Terminate") But you have not included a Func Terminate() ;; exit, or some other code you like to run in this case. EndFunc "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
Realm Posted July 13, 2010 Author Share Posted July 13, 2010 That was not the entire script but a mere example in which i believe the problem or solution may be found, I do have a Func Terminate() in my script, as with the other listed Functions, that is not the problem. The problem is that when the button "Run" is pressed, it goes to a Function that loops itself, however if the button 'Pause' or the $GUI_EVENT_CLOSE is pressed then nothing happens. It appears that a Function that loops itself, blocks the GUIOnEventMode. I was hoping someone else found a way around this, or even a better way to loop a function until something else happens in the GUI My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
KaFu Posted July 13, 2010 Share Posted July 13, 2010 In OnEventMode a called function MUST be finished before the next function can be called by an OnEvent trigger... if you've got a time consuming function started by a button click you'll see that the function is called as often as you click the button, not instantly but in the order of clicks. To circumvent this I use the Windows Messages. Those will be detected even if you're in a function triggered by OnEvent. Define a Global Pause Bool and check for this within your functions, e.g. in tight loops check for $b_Break = true and then return instantly (btw, I prefer to call my controls something like $c_FUNCTION_TYPE_NAME, makes it easier to find them later on if you script grows). expandcollapse popup#include <WindowsConstants.au3> #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) Global $b_Run = False Global $b_Pause = False $gui = GUICreate("CELLUBOT INSTALLER") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $c_Main_Button_Run = GUICtrlCreateButton("Run", 10, 10, 65, 20) GUICtrlSetOnEvent(-1, "RunApplication") $c_Main_Button_Pause = GUICtrlCreateButton("Pause", 95, 10, 65, 20) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 Sleep(1000) WEnd ;This is where my script gets lost in itself, and will not detect if the Pause or Terminated buttons have been pressed. Func RunApplication() if not $b_Run then Return ConsoleWrite(TimerInit() & @tab & "+START" & @crlf) _FirstFunction() EndFunc ;==>RunApplication Func _FirstFunction() while 1 sleep(200) ConsoleWrite("-" & TimerInit() & @tab & "Working..." & @crlf) while $b_Pause sleep(200) if not $b_Run then ExitLoop ConsoleWrite("!" & TimerInit() & @tab & "Pausing..." & @crlf) WEnd if not $b_Run then ConsoleWrite("+" & TimerInit() & @tab & "STOP" & @crlf) Return endif WEnd EndFunc Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam) $nNotifyCode = BitShift($wParam, 16) $nID = BitAND($wParam, 0x0000FFFF) $hCtrl = $lParam Switch $nID Case $c_Main_Button_Pause $b_Pause = Not $b_Pause If $b_Pause Then GUICtrlSetData($c_Main_Button_Pause, "Resume") Else GUICtrlSetData($c_Main_Button_Pause, "Pause") EndIf Case $c_Main_Button_Run $b_Run = Not $b_Run If $b_Run Then GUICtrlSetData($c_Main_Button_Run, "Stop") Else GUICtrlSetData($c_Main_Button_Run, "Run") EndIf EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND Func _Exit() Exit EndFunc OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Realm Posted July 17, 2010 Author Share Posted July 17, 2010 Thanks KaFu! I have been playing with this, since yesterday evening with my actual script, took awhile for me to understand how it worked. After hours of fun and frustration, I have a good understanding of it, and amazingly it is working pretty well in my script. Also with how you re-wrote _FirstFunction() was an excellant format, Taking that function from looping itself by calling itself at the end, and reformatting into a While Statement (its ok to laugh at my noobishness, I know I did), fixed a lot of other problems I was facing in my script. So thanks again for an excellent example that not only shown me how to fix the problem on hand, but in hindsight, also many other problems I was having at the same time My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. Link to comment Share on other sites More sharing options...
KaFu Posted July 17, 2010 Share Posted July 17, 2010 After hours of fun and frustration, I have a good understanding of it,Glad to hear that , thought this was one of the usual hit&run questions ...... from looping itself by calling itself at the endFunction recursion has to be considered truly evil in most circumstances, as it easily leads to endless loops. Sometimes it's the easiest way to do something, but if you use it better hand-over a depth counter (maybe as a function parameter) and build in a break. Max. recursion depth for AutoIt is currently 5100 (though the reference in the help-file says only something of call and executes? Not sure about that limit myself ). OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) 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