marko29 Posted February 25, 2011 Share Posted February 25, 2011 (edited) According to Interrupt Running Functions it is clearly possible to interrupt running function including While or Do loop as in example bellow... I am trying to do something like this with the MessageHandler Function, get the message, do the action in the function(*GuiRegisterMessage) even if while loop or do loop is currently on.So each time our thread receives message it will handle it right away and it wont care if while or do loop is running, as in the following example you can clearly see consolewrites running even while loop is currently on..I am trying to achieve something like this with the help of dll which sends the message(when needed) to my autoit gui. My Autoit Gui nicely receives it, and the GuiRegisterMessage function with debugging shows that it can process the message fine and do needed actions BUT if somewhere in my script there is while or do loop(something that i probably cant alternate as i really need it to finish some task) running the GuiRegisterMessage Function is Never Reached!. So i wonder why for some bloody reason this message handler function normally interrupts from wiki example but my SCRIPT will NOT do it.expandcollapse popup;EXAMPLE FROM AU3 WIKI(modified by me for readability) Register a message to intercept and its callback func[/b] 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) DO ConsoleWrite("waiting"&@LF) Sleep(30) Until $fInterrupt = 1 ; 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(1000) 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 _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 ConsoleWrite(">hjjgjgj" & @CRLF) Return $GUI_RUNDEFMSG EndFunc ;==>_WM_COMMANDAnd my example of GuiRegisterMessage which somehow wont go trough while or do loopexpandcollapse popupConsoleWrite("starting ..."&@LF) $moveon = 0 $maincount = _GUICtrlListView_GetItemCount($list) ConsoleWrite("sve skupa > " & $maincount & @CRLF) For $row = 0 To $maincount - 1 If $moveon = 2 Then ConsoleWrite("moveon is 2, exiting " & @CRLF) ExitLoop EndIf ConsoleWrite("clicking at index " & $row & @CRLF) Do .... .... Until _GUICtrlListView_GetItemSelected($list, $row) = True $pass = 1 while $pass = 1 ConsoleWrite("[u][b]waiting for $sub user message[/b][/u]..." & @CRLF) Sleep(1000) WEnd Next ; ThE function above i call first, it iterates trough listview, each time it clicks on a listview, message is invoked which is sent by dll to my script for checking, verying things... This is why i need this loop...Every time item is clicked i put a red light flag, when DLL receives update of listview item it sends back the greenlight flag to my gui that then moves on the next item etc.. etc.. So it would all be great if my msg handle function could actually move forward or [b]AT LEAST PASS A FLAG(WHICH IT CANT DO SINCE WHEN LOOP STARTS ITS NEVER CALLED)[/b] Const $sub_user = 99319 ; I send this custom message trough DLL to my gui, it is received normally(unless loops come along...) GUIRegisterMsg($sub_user, "_PLCallback") Func _PLCallback($hWnd, $Msg, $wParam, $lParam) Switch $Msg Case $sub_user ConsoleWrite("testing that we are here so i can put flag or do whatever..." & @CRLF) ...... EndSwitch Return 0 EndFuncSo thats it, Yours Sincerly ..Totally Sick of Debugging! Edited February 25, 2011 by marko29 Link to comment Share on other sites More sharing options...
wraithdu Posted February 25, 2011 Share Posted February 25, 2011 Are you sure that the GUI is not receiving the message? Maybe just your ConsoleWrite function is failing? Can you post some fully reproducible code? Post a short secondary AutoIt script as well that will just send the first script the message (so we don't need your DLL). Link to comment Share on other sites More sharing options...
marko29 Posted February 28, 2011 Author Share Posted February 28, 2011 I figured the cause, but no solution, it happens if function starts with timer, after that message is not received Check this topic 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