EmptySpace Posted May 27, 2012 Share Posted May 27, 2012 So there is example from wiki expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; Set a HotKey HotKeySet("x", "_Interrupt") ; Declare a flag $fInterrupt = 0 $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) ; Create a dummy control for the Accelerator to action when pressed $hAccelInterupt = GUICtrlCreateDummy() ; Set an Accelerator key to action the dummy control Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ] GUISetAccelerators($AccelKeys) GUISetState() ; Intercept Windows command messages with out own handler GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 _Func_1() Case $hButton_2 _Func_2() EndSwitch WEnd Func _Func_1() ; Make sure the flag is cleared $fInterrupt = 0 For $i = 1 To 20 ConsoleWrite("-Func 1 Running" & @CRLF) ; Look for the flag If $fInterrupt <> 0 Then ; The flag was set Switch $fInterrupt Case 1 ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF) Case 2 ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF) Case 3 ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF) EndSwitch Return EndIf Sleep(100) Next ConsoleWrite(">Func 1 Ended" & @CRLF) EndFunc Func _Func_2() For $i = 1 To 3 ConsoleWrite("+Func 2 Running" & @CRLF) Sleep(100) Next ConsoleWrite(">Func 2 Ended" & @CRLF) EndFunc Func _Interrupt() ; The HotKey was pressed so set the flag $fInterrupt = 2 EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; The Func 2 button was pressed so set the flag If BitAND($wParam, 0x0000FFFF) = $hButton_2 Then $fInterrupt = 1 ; The dummy control was actioned by the Accelerator key so set the flag If BitAND($wParam, 0x0000FFFF) = $hAccelInterupt Then $fInterrupt = 3 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND And there is for exmpl start and stop buttons. For example when you hit start it starts doing something like clicking mouse, navigating website, refreshing it million times. So I can delete all Consolewrite things here? I already found solution how to stop function but there is too much code and I dont know which I dont need. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <IE.au3> $fInterrupt = 0 $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Start", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("Stop", 10, 50, 80, 30) ; I need this part of code? $hAccelInterupt = GUICtrlCreateDummy() Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ] GUISetAccelerators($AccelKeys) ; GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 _Func_1() Case $hButton_2 _Func_2() EndSwitch WEnd Func _Func_1() $fInterrupt = 0 For $i = 1 To 10000 ; I can make while loop here? _IEAction($oIE,"refresh") ; I dont need this right? If $fInterrupt <> 0 Then Switch $fInterrupt Case 1 ConsoleWrite("!Func 1 interrrupted by Func 2" & @CRLF) Case 2 ConsoleWrite("!Func 1 interrrupted by HotKey" & @CRLF) Case 3 ConsoleWrite("!Func 1 interrrupted by Accelerator" & @CRLF) EndSwitch Return EndIf Sleep(100) Next ConsoleWrite(">Func 1 Ended" & @CRLF) ;this too EndFunc Func _Func_2() For $i = 1 To 2 ConsoleWrite("+Func 2 Running" & @CRLF) ;and these two? Sleep(100) Next ConsoleWrite(">Func 2 Ended" & @CRLF) EndFunc ;;;;i dont need this? I understand only that this thing waits for button click and sends comand to write something in console? Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) If BitAND($wParam, 0x0000FFFF) = $GUI_Button_Stop Then $fInterrupt = 1 If BitAND($wParam, 0x0000FFFF) = $hAccelInterupt Then $fInterrupt = 3 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Link to comment Share on other sites More sharing options...
PhoenixXL Posted May 27, 2012 Share Posted May 27, 2012 (edited) Function Interrupt will set $fInterrupt to such a Value(i.e. 2) which can be checked upon to find out how the Function was Closed/Exitted Since the x button is assigned to the Hotkey, the Function will receive $fInterrupt as 2 when x would be pressed and would exit The Second was Difficult to Read actually i wasnt getting what u were doin therefore i left that part and Please Tell what u really and exactly want to do Regards Phoenix XL Edited May 27, 2012 by PhoenixXL 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...
EmptySpace Posted May 27, 2012 Author Share Posted May 27, 2012 I already explained what I want. I just want to remove everything which i dont need like consolewrite Link to comment Share on other sites More sharing options...
PhoenixXL Posted May 29, 2012 Share Posted May 29, 2012 _Func_1() Returns $fInterrupt when func_2 or accelerator or hotkey will get executed on no interruption _Func_1() returns 0 your simplified code: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ; Set a HotKey HotKeySet("x", "_Interrupt") ; Declare a flag $fInterrupt = 0 $hGUI = GUICreate("Test", 500, 500) $hButton_1 = GUICtrlCreateButton("Func One", 10, 10, 80, 30) $hButton_2 = GUICtrlCreateButton("Func Two", 10, 50, 80, 30) ; Create a dummy control for the Accelerator to action when pressed $hAccelInterupt = GUICtrlCreateDummy() ; Set an Accelerator key to action the dummy control Dim $AccelKeys[1][2]=[ ["z", $hAccelInterupt] ] GUISetAccelerators($AccelKeys) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton_1 _Func_1() Case $hButton_2 $fInterrupt = 1 Case $hAccelInterupt $fInterrupt = 3 EndSwitch WEnd Func _Func_1() ; Make sure the flag is cleared $fInterrupt = 0 For $i = 1 To 20 If Not $fInterrupt Then Return $fInterrupt Sleep(100) Next Return 0 EndFunc Func _Interrupt() ; The HotKey was pressed so set the flag $fInterrupt = 2 EndFunc 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...
EmptySpace Posted May 29, 2012 Author Share Posted May 29, 2012 Also I dont need any hotkeys, interrupt it only with button2. We are going on that way. I wanted to shorten code when i try it myself i delete wrong things and it even dont work or its buggy. Link to comment Share on other sites More sharing options...
EmptySpace Posted May 29, 2012 Author Share Posted May 29, 2012 Solved. Thanks PhoenixXL for help. Clean code for stopping func : expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $fInterrupt = False $Form1 = GUICreate("Form1", 263, 168, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 33) $Button2 = GUICtrlCreateButton("Button2", 96, 9, 75, 31) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Run_Func_1() EndSwitch WEnd Func _Run_Func_1() ConsoleWrite("Running Func_1" & @CRLF) While 1 Sleep(10) If $fInterrupt Then $fInterrupt = False ConsoleWrite("Stopping Func_1" & @CRLF) Return EndIf WEnd EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; Button2 was pressed so set the flag If BitAND($wParam, 0x0000FFFF) = $Button2 Then $fInterrupt = True Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Link to comment Share on other sites More sharing options...
PhoenixXL Posted May 31, 2012 Share Posted May 31, 2012 Why are u registering the message u can already use it in the msgloop, try this code #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $fInterrupt = False $Form1 = GUICreate("Form1", 263, 168, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 33) $Button2 = GUICtrlCreateButton("Button2", 96, 9, 75, 31) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 _Run_Func_1() Case $Button2 $fInterrupt = True ;Do Something... EndSwitch WEnd Func _Run_Func_1() ConsoleWrite("Running Func_1" & @CRLF) While 1 Sleep(10) If $fInterrupt Then $fInterrupt = False ConsoleWrite("Stopping Func_1" & @CRLF) Return EndIf WEnd EndFunc 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...
Moderators Melba23 Posted May 31, 2012 Moderators Share Posted May 31, 2012 PhoenixXL,Have you tried that code you posted? I think not because it does not work - once AutoIt is within a function you cannot use other controls to break into that function directly. Take a look at the Interrupting a running function tutorial in the Wiki to learn more. 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...
PhoenixXL Posted June 2, 2012 Share Posted June 2, 2012 M23, it will not actually interrupt the Function but since the function has a while loop in it , the while loop will not be executed again after the respective functions and commands 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...
Moderators Melba23 Posted June 2, 2012 Moderators Share Posted June 2, 2012 PhoenixXL,it will not actually interrupt the FunctionSo you agree that it does not do what the OP wants then! 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...
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