EmptySpace Posted January 8, 2013 Share Posted January 8, 2013 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $fInterrupt = 0 #Region ### START Koda GUI section ### Form= $Interrupt = GUICreate("Interrupt", 316, 86, 192, 124) $Stop = GUICtrlCreateButton("Stop", 9, 8, 63, 49) $st = GUICtrlCreateLabel("", 84, 24, 180, 28) $start = GUICtrlCreateButton("start", 8, 56, 67, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start start() EndSwitch WEnd Func start() GUICtrlSetData($st,"Sleeping...Zzz...") While 1 Sleep(500) ;============================================ If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetData($st,"Stop button pressed..Stoping..") $fInterrupt = 0 GUICtrlSetData($st,"Not working") exitloop Case 2 GUICtrlSetData($st,"Exiting directly...") Exit EndSwitch Endif ;============================================ Wend endfunc ;===================================================================================================================================================================== ; STOP FUNCTIONS ;===================================================================================================================================================================== Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; Stop was pressed so set the flag (GUI) If BitAND($wParam, 0x0000FFFF) = $stop Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND FOR BUTTON Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam) ; Closure [X} pressed If BitAND($wParam, 0xFFF0) = 0xF060 Then ; $SC_CLOSE $fInterrupt = 2 EndIf Return $GUI_RUNDEFMSG EndFunc ;==>On_WM_SYSCOMMAND In most of codes I use like this: DO SOMETHING ;============================================ If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetData($st,"Stop button pressed..Stoping..") $fInterrupt = 0 GUICtrlSetData($st,"Not working") exitloop Case 2 GUICtrlSetData($st,"Exiting directly...") Exit EndSwitch Endif ;============================================ DO SOMETHING ;============================================ If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetData($st,"Stop button pressed..Stoping..") $fInterrupt = 0 GUICtrlSetData($st,"Not working") exitloop Case 2 GUICtrlSetData($st,"Exiting directly...") Exit EndSwitch Endif ;============================================ DO SOMETHING So its looks very bad.. Putting it in func would be better but it wont work becouse exitloop works only in loop. ;Do something interrupt() ;Do something interrupt() ;Do something It would be better.. Any ideas? Edited January 8, 2013 by EdgarT Link to comment Share on other sites More sharing options...
EndFunc Posted January 8, 2013 Share Posted January 8, 2013 Not sure of your question, but if you are in a Function, then you want to use Return to exit the function instead of exitloop. It will stop the execution of the remaining function. You can also return values e.g. Return $variable. Hope that helps. EndFuncAutoIt is the shiznit. I love it. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 8, 2013 Moderators Share Posted January 8, 2013 EdgarT, Does this do what you want? expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $fInterrupt = 0 $Interrupt = GUICreate("Interrupt", 316, 86, 192, 124) $Stop = GUICtrlCreateButton("Stop", 9, 8, 63, 49) $st = GUICtrlCreateLabel("", 84, 24, 180, 28) $start = GUICtrlCreateButton("start", 8, 56, 67, 25) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $start start() EndSwitch WEnd Func start() GUICtrlSetData($st, "Sleeping...Zzz...") While 1 ; Do something GUICtrlSetData($st, "Doing something!") Sleep(1000) GUICtrlSetData($st, "Checking for interrupt" & @CRLF) Sleep(100) If _Interrupt() Then ExitLoop GUICtrlSetData($st, "Doing something!") Sleep(1000) GUICtrlSetData($st, "Checking for interrupt" & @CRLF) Sleep(100) If _Interrupt() Then ExitLoop Sleep(1000) GUICtrlSetData($st, "Doing something!") Sleep(1000) GUICtrlSetData($st, "Checking for interrupt" & @CRLF) Sleep(100) If _Interrupt() Then ExitLoop WEnd EndFunc ;==>start ;===================================================================================================================================================================== ; STOP FUNCTIONS ;===================================================================================================================================================================== Func _Interrupt() If $fInterrupt Then Switch $fInterrupt Case 1 GUICtrlSetData($st, "Stop button pressed..Stoping..") $fInterrupt = 0 GUICtrlSetData($st, "Not working") Return True Case 2 GUICtrlSetData($st, "Exiting directly...") Exit EndSwitch EndIf Return False EndFunc ;==>_Interrupt Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; Stop was pressed so set the flag (GUI) If BitAND($wParam, 0x0000FFFF) = $Stop Then $fInterrupt = 1 Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMAND Func _WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam) ; Closure [X} pressed If BitAND($wParam, 0xFFF0) = 0xF060 Then ; $SC_CLOSE $fInterrupt = 2 EndIf Return $GUI_RUNDEFMSG EndFunc ;==>_WM_SYSCOMMAND Please ask if you have any questions - or I have misunderstood. 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...
EmptySpace Posted January 8, 2013 Author Share Posted January 8, 2013 Ahh.. It was so easy.. Thank you melba! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 8, 2013 Moderators Share Posted January 8, 2013 EdgarT, Glad to see my crystal ball is still working as designed! 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