goldenix Posted November 30, 2007 Share Posted November 30, 2007 (edited) Hi I would like to jump out of this _main() function if I press cancel so that it will go back to ;keep program alive loop. Then I can call the _main() function any time again. is something like this possibe at all?What i dont understand is this: if I make the code, then I put ;keep prog alive loop at the end of it & I can press any button, but if I make make a hotkey to a function with a copy of this keep alive loop, its not working anymore...(I cant press any buttons while its inside of that loop.) I wonder if there isnt something like EXITFUNCTION...?Someone said this, But How on earth would I do that?to use a button to start a long running task and allow cancelling it via another button. Essentially, the trick is to structure your program so that instead of having a dummy While loop to keep the program going while GUI Events are fired, you set up your long running task to run inside the While loop but you use a global flag to keep it from running. Something like this would allow you to load a big file but cancel loading (Pseudo-code):But ok lets say I cant do that with buttons What about Hotkeys? How do I exit this function with a hotkey, without exiting the script & being able to call the main function again anytime?#include <GUIConstants.au3> Opt("GUICoordMode",2) Opt("GUIResizeMode", 1) Opt("GUIOnEventMode", 1) $parent1 = GUICreate("Parent1") $ok1 = GUICtrlCreateButton ("OK", 10, 30, 50) GUICtrlSetOnEvent(-1, "_main") $cancel1 = GUICtrlCreateButton ( "Cancel", 0, -1) GUICtrlSetOnEvent(-1, "_CancelPressed") GUISetState(@SW_SHOW) Global $count Func _main() $count = 1 While 1 Sleep(500) _OKPressed() $count += 1 Wend EndFunc Func _OKPressed() ToolTip('OK_func1_' & $count,0,0) EndFunc Func _CancelPressed() MsgBox(1,'', 'Pressed Cancel') ;~ Exit EndFunc ;keep program alive loop While 1 GuiSetState() Wend Edited November 30, 2007 by goldenix My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
Richard Robertson Posted November 30, 2007 Share Posted November 30, 2007 Ah yes, the good old EXITFUNCTION. It's called Return. Link to comment Share on other sites More sharing options...
goldenix Posted November 30, 2007 Author Share Posted November 30, 2007 Ah yes, the good old EXITFUNCTION. It's called Return.Guess its not possible to do the same with buttons, must be autoit bug... see the sample: expandcollapse popup#include <GUIConstants.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("AForm1", 327, 70, 193, 115) GUISetOnEvent($GUI_EVENT_CLOSE, "AForm1Close") $Label1 = GUICtrlCreateLabel('', 152, 16, 20, 17) $go = GUICtrlCreateButton ( "go", 10, -1) $cancel = GUICtrlCreateButton ( "Cancel", 50, -1) GUICtrlSetOnEvent($go, "_main") GUICtrlSetOnEvent($cancel, "_CancelPressed") GUISetState(@SW_SHOW) Global $i _main() ; Remove this line & this wont work $i=1 Func _main() $exitloop = 0 While 1 $i +=1 GUICtrlSetData($Label1, $i) Sleep(100) WEnd EndFunc Func _CancelPressed() MsgBox(4096,"","cancelled.",1) EndFunc Func AForm1Close() Exit EndFunc While 1 Sleep(0x7fffffff) WEndoÝ÷ ÙªÝFÞ®Û(º¹í©ñq©ÞÆ+_ºw-ðØZ¶W²Ý°k+Êë" '(h¶G²²Øhø«zZqêÞ¶êçÂ+a{)Ü"VÞ±©*ÞÌ(®H§Êyú+¶¬ºÈ§-ì¬jëh×6#include <GUIConstants.au3> HotKeySet("{PAUSE}", "_Hotkey") Opt("GUIOnEventMode", 1) $Form1 = GUICreate("AForm1", 327, 70, 193, 115) GUISetOnEvent($GUI_EVENT_CLOSE, "AForm1Close") $Label1 = GUICtrlCreateLabel('', 152, 16, 20, 17) $go = GUICtrlCreateButton ( "go", 10, -1) $cancel = GUICtrlCreateButton ( "Cancel", 50, -1) GUICtrlSetOnEvent($go, "_main") GUICtrlSetOnEvent($cancel, "_CancelPressed") GUISetState(@SW_SHOW) Global $return, $i $i=1 Func _main() $return = 0 While 1 $i +=1 GUICtrlSetData($Label1, $i) If $return =1 Then Return Sleep(100) WEnd EndFunc Func _Hotkey() $return = 1 EndFunc Func _CancelPressed() MsgBox(4096,"","cancelled.") Exit EndFunc Func AForm1Close() Exit EndFunc While 1 Sleep(0x7fffffff) WEnd My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] 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