Jump to content
Sign in to follow this  

While or Do Loop supressing MsgHandler function

Recommended Posts

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.

;EXAMPLE FROM AU3 WIKI(modified by me for readability)

Register a message to intercept and its callback func[/b]

while 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
        Case $hButton_1
        Case $hButton_2

Func _Func_1()
    ; Make sure the flag is cleared
    $fInterrupt = 0
    For $i = 1 To 20
        ConsoleWrite("-Func 1 Running" & @CRLF)
        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)
    ConsoleWrite(">Func 1 Ended" & @CRLF)

Func _Func_2()
    For $i = 1 To 3
        ConsoleWrite("+Func 2 Running" & @CRLF)
    ConsoleWrite(">Func 2 Ended" & @CRLF)

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)
EndFunc   ;==>_WM_COMMAND

And my example of GuiRegisterMessage which somehow wont go trough while or do loop

ConsoleWrite("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)

        ConsoleWrite("clicking at index " & $row & @CRLF)

        Until _GUICtrlListView_GetItemSelected($list, $row) = True
        $pass = 1

        while $pass = 1
            ConsoleWrite("[u][b]waiting for $sub user message[/b][/u]..." & @CRLF)


; 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)



    Return 0


So thats it,

Yours Sincerly ..

Totally Sick of Debugging!

Edited by marko29

Share this post

Link to post
Share on other sites

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).

Share this post

Link to post
Share on other sites

I figured the cause, but no solution, it happens if function starts with timer, after that message is not received

Check this topic

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...