Jump to content

AutoIT suspends on Window Title, scrollbar click


Recommended Posts

Hi, I'm just wondering why this happens in an AutoIT program with a GUI:

Clicking the title bar, the minimize,maximize, 'x' (close), system menu, or any scrollbars (without movement) causes the entire script to come to a halt - save for callback routines and any created threads (my new pet project).

Is this a problem with the way the GUI handling was done, or is there something more to it? All I know from searching is that people have made workarounds for it (like capturing the click button and seeing if it was on the title bar, etc), but that doesn't seem like a good idea if there's something broken in AutoIT's code.

Anyway, any information as to why this happens would be helpful, thanks.

Link to comment
Share on other sites

This has nothing to do with autoit.

Windows blocks the thread that created the window when the user do action like these. However window still calls the winproc for the window during this time (this is why functions registered with GUIRegisterMsg and callbacks are still executed).

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Monoceres,

Hmm, that seems like bad practice on Windows part (and probably why some programs create their own 'title bar' or other GUI elements).

Now - THREAD, you say? hmm.. so what if I create a window with a separately created thread? Will it only affect that thread and allow AutoIT to continue? I suppose that's probably a bit more complex than one would like though - the thread would have to handle all the messages sent, correct? That wouldn't work out well.

So what do we do when we want our script to continue updating the window (and running).. just create a bunch of Global variables and setup the callbacks I guess?

Link to comment
Share on other sites

Richard,

Hmm.. so AutoIT is handling the message then, but preventing the other code from executing? I'm still unclear about all the behind-the-scenes stuff in Windows GUI's, which is why I usually keep my nose out of it. But it's certainly annoying when your code just stops when someone clicks a certain area of the window!

Link to comment
Share on other sites

Every script I've used that has a GUI has the same behavior - *everything* stops until the mouse is released. This includes the Adlib functions, but the Reistered callback/hook functions seem to be unaffected (as well as, of course, my own created Threads).

Thanks

Link to comment
Share on other sites

That's normal. It's how windows handle things. What happens with what and what's blocked is determined very precisely. Even a window (control) class is important. Run this code to see some ways:

#include <Memory.au3>

Global $pRemoteCode = _MemVirtualAlloc(0, 914, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)

Global $hGui = GUICreate("Testing")

GUICtrlCreateLabel("- AVI is not blocked on title bar or ALT, but is on buttons:", 10, 25, 300, 22)
GUICtrlSetFont(-1, -1, -1, 4)

Global $hAVI = GUICtrlCreateAvi("shell32.dll", 165, 50, 50, 272, 60)
GUICtrlSetState($hAVI, 1)

GUICtrlCreateLabel("- Things in 'our thread' always are:", 10, 150, 200, 22)
GUICtrlSetFont(-1, -1, -1, 4)

Global $hLabel = GUICtrlCreateLabel("Moving label", 0, 180, 140, 30)
GUICtrlSetFont($hLabel, 16, 800)
GUICtrlSetColor($hLabel, 0x0000CC)

GUICtrlCreateLabel("- Execute in another thread (mission impossible?). Nothing is blocked here:", 10, 250, 380, 22)
GUICtrlSetFont(-1, -1, -1, 4)

Global $hButton = GUICtrlCreateButton("Do something in another thread", 20, 290, 200, 30)

GUICtrlCreateLabel("Pres ALT or click and hold GUI title bar", 230, 370, 170, 22)
GUICtrlSetFont(-1, 7, -1, 2)

Global $iX, $iMove

GUISetState()

While 1
    Switch GUIGetMsg()
        Case - 3
            Exit
        Case $hButton
            _BeepInAnotherThread_MissionImpossible()
    EndSwitch

    If Mod(@MSEC, 5) Then
        $iMove = 1
    Else
        If $iMove Then
            GUICtrlSetPos($hLabel, $iX, 180)
            $iX += 1
            If $iX = 200 Then $iX = 0
            $iMove = 0
        EndIf
    EndIf

WEnd










Func _BeepInAnotherThread_MissionImpossible()

    Local $hKernel32 = _WinAPI_GetModuleHandle("kernel32.dll")

    Local $aBeep = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hKernel32, "str", "Beep")
    Local $pBeep = $aBeep[0]
    Local $sBeep = SwapEndian($pBeep)

    Local $aSleep = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hKernel32, "str", "Sleep")
    Local $pSleep = $aSleep[0]
    Local $sSleep = SwapEndian($pSleep)

    Local $tCodeBuffer = DllStructCreate("byte[516]; byte[398]", $pRemoteCode) ; two arrays to avoid yacc stack overflow

    Local $sDelay1 = SwapEndian(75)
    Local $sDelay2 = SwapEndian(150)
    Local $sDelay3 = SwapEndian(300)
    Local $sDelay4 = SwapEndian(1200)
    Local $sDelay5 = SwapEndian(225)

    Local $sToneA4h = SwapEndian(466)
    Local $sToneC5 = SwapEndian(523)
    Local $sToneC5h = SwapEndian(554)
    Local $sToneD5 = SwapEndian(587)
    Local $sToneD5h = SwapEndian(622)
    Local $sToneE5 = SwapEndian(659)
    Local $sToneF5 = SwapEndian(698)
    Local $sToneF5h = SwapEndian(740)
    Local $sToneG5 = SwapEndian(784)
    Local $sToneA5h = SwapEndian(932)
    Local $sToneC6 = SwapEndian(1047)

    DllStructSetData($tCodeBuffer, 1, _
            "0x" & _
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5h & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneD5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneE5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneF5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push duration
            "68" & $sToneF5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay5 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay3 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneA5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneC6 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay3 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay3 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneF5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneF5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay3 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay3 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneA5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "")

    DllStructSetData($tCodeBuffer, 2, _
            "0x" & _
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneA5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneC6 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay3 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay3 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneF5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneF5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneA5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay4 & _                                  ; push duration
            "68" & $sToneD5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneA5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay4 & _                                  ; push duration
            "68" & $sToneC5h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay1 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneA5h & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneG5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay4 & _                                  ; push duration
            "68" & $sToneC5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push Milliseconds
            "B8" & $sSleep & _                                   ; mov eax, [Sleep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneA4h & _                                 ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "68" & $sDelay2 & _                                  ; push duration
            "68" & $sToneC5 & _                                  ; push freq
            "B8" & $sBeep & _                                    ; mov eax, [Beep]
            "FFD0" & _                                           ; call eax
            "C3" _                                               ; ret
            )

    Local $aCall = DllCall("kernel32.dll", "ptr", "CreateThread", "ptr", 0, "dword", 0, "ptr", $pRemoteCode, "ptr", 0, "dword", 0, "dword*", 0)

    Local $hThread = $aCall[0]

    Return $hThread

EndFunc   ;==>_BeepInAnotherThread_MissionImpossible



Func SwapEndian($iValue)
    Return Hex(BinaryMid($iValue, 1, 4))
EndFunc   ;==>SwapEndian
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

That's normal. It's how windows handle things. What happens with what and what's blocked is determined very precisely. Even a window (control) class is important. Run this code to see some ways:

trancexx, haha, great example! Mission Impossible in a thread haha..

Anyway.. I'm starting to understand it.. I think. If there was some place that explained it clearly, that would help.

Hmm.. a quick search resulted in -> this<- but I'm pretty sure those messages in the 5th reply aren't sent by GUIGetMsg(), so I'd have to make a callback proc eh..

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...