EmptySpace Posted May 28, 2012 Posted May 28, 2012 (edited) So the best example #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 263, 168, 192, 124) $Button1 = GUICtrlCreateButton("Button1", 8, 8, 75, 33) $Button2 = GUICtrlCreateButton("Button2", 96, 9, 75, 31) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 while 1 sleep(200) Wend Case $Button2 MsgBox(0,"What the hell?","Why this wont pop up?") EndSwitch WEnd When you hit Button1 it starts function and while that one is running its impossible to open msgbox by hitting button2. Why? And its possible to change it? Oh, maybe change switch or something? Im sure that its possible! Edited May 28, 2012 by Edgaras
czardas Posted May 28, 2012 Posted May 28, 2012 You can only run multiple processes on multi-core processors. In order to achieve what you want you need to interrupt the first function. There are several ways to do this. Fisrt you should read this wiki article. operator64 ArrayWorkshop
EmptySpace Posted May 28, 2012 Author Posted May 28, 2012 I want to run function while one function is already running. Hmm I used info from that wiki to stop functions. So you mean I have to stop already running function to open that msg box and then continue main function? Can you write me some short code? Im really lost in that interrupting running function.
Moderators Melba23 Posted May 28, 2012 Moderators Posted May 28, 2012 Edgaras, Can you write me some short code?As you can see from the Wiki tutorial it is not easy to interrupt a running function. But in the script example you have posted you are not running a function. It is quite possible to do what you want very easily - it took me about 30 secs to code it. #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $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 ConsoleWrite("Running" & @CRLF) While 1 Sleep(10) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 MsgBox(0, "What the hell?", "Why this now pops up!") EndSwitch WEnd EndSwitch WEnd All clear now? Or was that not what you are really trying to do? 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
EmptySpace Posted May 29, 2012 Author Posted May 29, 2012 (edited) Nah, I think I need to interrupt func. I used while 1 sleep(200) Wendlike function . When sleep is sleeping forever I cant open msgbox. So i need to use that interrupt to stop sleep after msg box appears continue sleep. Edited May 29, 2012 by Edgaras
Moderators Melba23 Posted May 29, 2012 Moderators Posted May 29, 2012 Edgaras, So the best exampleWhereas the example was actually nothing like the code you want to use. If you want help then please make sure that the code you provide is as close as possible to what you really want - otherwise we all waste a lot of time posting solutions which do not meet your requirements. This is how you can interrupt your function and then let it continue: 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) ; You will have to run something like this at regular intervals in your function If $fInterrupt Then $fInterrupt = False _Run_Func_2() EndIf WEnd EndFunc Func _Run_Func_2() ConsoleWrite("Pausing Func_1" & @CRLF) ConsoleWrite("Running Func_2" & @CRLF) Sleep(1000) ConsoleWrite("Continuing Func_1" & @CRLF) 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 If your function does not offer regular opportunities to check for the interrupt flag then you are going to find it very difficult to break into the running function and you may have to rethink your code. 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
EmptySpace Posted May 29, 2012 Author Posted May 29, 2012 "we all waste a lot of time posting solutions which do not meet your requirements." all codes is useful for me. In pc I have folders where I put examples and all codes is very usefull. Ok, I got what I want. But now i dont understand ConsoleWrite. It only writes some text to show me smthg or this is important to code? I can delete it if i dont need, right?
Moderators Melba23 Posted May 29, 2012 Moderators Posted May 29, 2012 Edgaras,all codes is useful for meA rather selfish attitude if I may say so - working on something for you which is not directly relevant to your problem means that someone else might not be getting their question resolved. So please do make your code as close as possible to what you really want - that way we can give you the correct answer as soon as possible. The ConsoleWrite lines are only there to show you what is going on - you have no need to use them in your final script. 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
EmptySpace Posted May 29, 2012 Author Posted May 29, 2012 Ok. So in same way I can stop func just need edit _Run_Func_2?
Moderators Melba23 Posted May 29, 2012 Moderators Posted May 29, 2012 Edgaras, So in same way I can stop func just need edit _Run_Func_2?I am not sure what you mean. If you want to stop the Func_1 function then you just use Return - there is no need for the second function at all: 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 All clear? 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
czardas Posted May 29, 2012 Posted May 29, 2012 In the code from Melba, you don't stop function 1. Instead it is interrupted while you run function 2. Study Melba's examples. operator64 ArrayWorkshop
EmptySpace Posted May 29, 2012 Author Posted May 29, 2012 Thanks! Now I know what I wanted to know . Got clear code. I asked in other topic for help to make clear code without unneeded things.
EmptySpace Posted May 29, 2012 Author Posted May 29, 2012 How I should make that when I click [X] buton it stops func and exits program? I have to interrupt func? Or it can directly hit X and terminate script?
Moderators Melba23 Posted May 29, 2012 Moderators Posted May 29, 2012 Edgaras, Just intercept the closure message like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $fInterrupt = 0 $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") GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND") 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 Switch $fInterrupt Case 1 ConsoleWrite("Stopping Func_1" & @CRLF) $fInterrupt = 0 Return Case 2 ConsoleWrite("Exiting directly" & @CRLF) Exit EndSwitch EndIf WEnd EndFunc Func _WM_COMMAND($hWnd, $Msg, $wParam, $lParam) ; Button2 was pressed so set the flag If BitAND($wParam, 0x0000FFFF) = $Button2 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 ConsoleWrite("WM_Close intercepted" & @CRLF) EndIf Return $GUI_RUNDEFMSG EndFunc ;==>On_WM_SYSCOMMAND All clear? 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
EmptySpace Posted May 29, 2012 Author Posted May 29, 2012 Thanks it works. But now im stucked on adding some code Func myfunc() _GUICtrlButton_Enable($Button4, False) ConsoleWrite("Running Func_1" & @CRLF) While 1 ;;;;;;;;;;;;code;;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;code;;;;;;;;; $body = _IEBodyReadHTML($oIE) Sleep(4500) _IEAction($oIE, "refresh") If StringInStr($body, "Some text") Then MsgBox(0,"Error","No match") If StringInStr($body, "Some text") Then MsgBox(0,"Error","Also No match") ; how I can do some if here? Every time i try then it works but then I cant use $fInterrupt button or [X] button. Should I make this with cases or what? Also how I should stop function? Hmm start interrupt func. If StringInStr($body, "Some text") Then MsgBox(0,"Error","Also No match") ;----------><----------- here? Something like $fInterrupt = 0? ;;;;;;;;;;;;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;; If $fInterrupt Then Switch $fInterrupt Case 1 $fInterrupt = 0 Return Case 2 Exit EndSwitch EndIf WEnd EndFunc
Moderators Melba23 Posted May 29, 2012 Moderators Posted May 29, 2012 Edgaras, Perhaps something like this will work for you - obviously I have not tested it: Func myfunc() _GUICtrlButton_Enable($Button4, False) ConsoleWrite("Running Func_1" & @CRLF) While 1 ;;;;;;;;;;;;code;;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;code;;;;;;;;;;;;;;;;code;;;;;;;;; $body = _IEBodyReadHTML($oIE) ; Use this 4.5 sec delay to look for the flag Local $iBegin = TimerInit() ; Set a timestamp Do Sleep(10) If $fInterrupt Then ; Check for the flag Switch $fInterrupt Case 1 $fInterrupt = 0 Return Case 2 Exit EndSwitch EndIf Until TimerDiff($iBegin) > 4500 ; Loop until the delay is ended ; Now do the checks on the HTML _IEAction($oIE, "refresh") If StringInStr($body, "Some text ") Then MsgBox(0, "Error", "No match") If StringInStr($body, "Some text") Then MsgBox(0, "Error", "Also No match") If StringInStr($body, "Some text") Then MsgBox(0, "Error", "Also No match") EndIf EndIf EndIf WEnd EndFunc ;==>myfunc 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
EmptySpace Posted May 29, 2012 Author Posted May 29, 2012 I cant understand half of these things. Anyway im going to study autoit for a while as I finished exams Also how I can stop func if string is not found? It would stop automatically without pushing any button. $fInterrupt = True ???
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