Jump to content

Unknown window appears during script run

Recommended Posts



I have wrote a script which capture 4 different regions on the screen then try to find a specific image in these regions and in case of success changes label text in my GUI. For screen scraping and image comparison script uses _ScreenCapture and FindBMP function.

I put it in a loop with 1 second break.

And all works great while after a couple of minutes hidden window appears and my script freezes. No text, no messages, no titles. When I try to close this window from windows taskbar it blinks on the center of the screen and hides again. Only “End Task” from task manages can close this window and script.

The situation is the same when run it form SciTE or as EXE file. I also tried 2 different versions of Autoit, newest and previous.

I can’t understand the cause of the problem. Is it a FindBMP function error or some overflow? Strange that it appears in a couple of minutes after totally normal work (images in the regions found and label changes continuously). I also tried to stop and start scanning every 1 min with help of buttons in GUI and nothing helps. Hidden window appears in 5-10 mins.

Please advice from what steps I have to start to remove this window. Do I need to upload all script here?


Edited by likehu

Share this post

Link to post
Share on other sites

Yes, agree  :) but i can't find anything about this window.

Here is my image finder script.

All other files (bmp icons ant ini file with coordinates) in the zip file in attachment. So I have started script in the SciTE or with EXE and after 5-10 mins that window blinks on desktop and dissappears. And script freezes.

Just to explain shortly what this script does. There are 6 different icons and 4 big main areas on desktop and script try to find each icon on specific area inside every big main area. All this done in For..Next loop.

Please help.

#pragma compile(Console, False)
#pragma compile(x64, True)
#pragma compile(Compatibility, Win10)
#pragma compile(Stripper, True)

AutoItSetOption("GuiOnEventMode", 1)

#Region Variables
;~ Const $bDebug = True
Const $bDebug = False
Const $cMatchLinePercentage = 0.99 ;Minimum matching, put on 1 if exact matching is needed on all lines

;~ Constants for type of picture matching
Const $c24RGBFullMatch = 1 ;Load as 24 bits and full match
Const $c24RGBPartialMatch = 2 ;Load as 24 bits and partial match
Const $c16RGBFullMatch = 3 ;Load as 16 bits and full match
Const $c16RGBPartialMatch = 4 ;Load as 16 bits and partial match

;~ array with BMP coords for every room
Global $aBMPCoords[7][21][2]

Global $cLB         ;search area coord for left begin
Global $cLE         ;search area coord for left end
Global $cTB         ;search area coord for top begin
Global $cTE         ;search area coord for top end

Global $fBMPSample
Global $bSearchResult

Global $Form1_1, $btnStart, $btnStop, $btnExit, $startFlag
#EndRegion Variables

#Region Includes
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <string.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <bmpsearch.au3>
#EndRegion Includes

#Region ### START Koda GUI section ### Form=
$Form1_1 = GUICreate("Jonny", 194, 314, -510, 11)
GUISetOnEvent($GUI_EVENT_CLOSE, "_exit")

$lblt1 = GUICtrlCreateLabel("Table 1", 24, 16, 40, 17)
$lblt2 = GUICtrlCreateLabel("Table 2", 128, 16, 40, 17)
$lblt3 = GUICtrlCreateLabel("Table 3", 24, 104, 40, 17)
$lblt4 = GUICtrlCreateLabel("Table 4", 128, 104, 40, 17)

$lblr1 = GUICtrlCreateLabel("", 4, 40, 84, 20, $WS_BORDER)
$lblr2 = GUICtrlCreateLabel("", 100, 40, 84, 20, $WS_BORDER)
$lblr3 = GUICtrlCreateLabel("", 4, 128, 84, 20, $WS_BORDER)
$lblr4 = GUICtrlCreateLabel("", 100, 128, 84, 20, $WS_BORDER)

$btnStart = GUICtrlCreateButton("Start", 16, 272, 75, 25)
GUICtrlSetOnEvent(-1, "start")

$btnStop = GUICtrlCreateButton("Stop", 16, 240, 75, 25)
GUICtrlSetOnEvent(-1, "stop")

$btnExit = GUICtrlCreateButton("Exit", 104, 272, 75, 25)
GUICtrlSetOnEvent(-1, "_exit")

$dmyInterrupt = GUICtrlCreateDummy()
GUICtrlSetOnEvent($dmyInterrupt, "interrupt")
GUIRegisterMsg($WM_COMMAND, "interrupt")

#EndRegion ### END Koda GUI section ###


Func Main()
    While 1
EndFunc   ;==>Main

Func start()
    $startFlag = True
    GUICtrlSetState($btnStart, $GUI_DISABLE)

    While $startFlag
EndFunc   ;==>start

Func f_ReadTables()
    $start = TimerInit()

    For $t = 1 To 4         ;check each of the 4 big main areas
        Local $Counter = 0, $LabelPoinet

        For $i = 1 To 6     ;insert needed coordinates for each icon depends of the number of big main area
            Switch $t
                Case 1
                    $cLB = Number($aBMPCoords[$i][5][1])
                    $cLE = Number($aBMPCoords[$i][6][1])
                    $cTB = Number($aBMPCoords[$i][7][1])
                    $cTE = Number($aBMPCoords[$i][8][1])
                    $LabelPoinet = $lblr1
                Case 2
                    $cLB = Number($aBMPCoords[$i][9][1])
                    $cLE = Number($aBMPCoords[$i][10][1])
                    $cTB = Number($aBMPCoords[$i][11][1])
                    $cTE = Number($aBMPCoords[$i][12][1])
                    $LabelPoinet = $lblr2
                Case 3
                    $cLB = Number($aBMPCoords[$i][13][1])
                    $cLE = Number($aBMPCoords[$i][14][1])
                    $cTB = Number($aBMPCoords[$i][15][1])
                    $cTE = Number($aBMPCoords[$i][16][1])
                    $LabelPoinet = $lblr3
                Case 4
                    $cLB = Number($aBMPCoords[$i][17][1])
                    $cLE = Number($aBMPCoords[$i][18][1])
                    $cTB = Number($aBMPCoords[$i][19][1])
                    $cTE = Number($aBMPCoords[$i][20][1])
                    $LabelPoinet = $lblr4
                Case Else

            $fBMPSample = @ScriptDir & $aBMPCoords[$i][3][1]
            f_Shots($aBMPCoords[$i][1][1], $fBMPSample, $cLB, $cLE, $cTB, $cTE)

            If $bSearchResult = False Then
                $Counter = $Counter + 1
                $Counter = 0
                GUICtrlSetData($LabelPoinet, $aBMPCoords[$i][1][1])

        If $Counter = 6 Then
            GUICtrlSetData($LabelPoinet, '')
EndFunc   ;==>f_ReadTables

Func f_Shots($RoomName, $SearchBMP, $cLB, $cTB, $cLE, $cTE)
    $hBMP = _ScreenCapture_Capture('', $cLB, $cTB, $cLE, $cTE, False)
    $bSearchResult = findBMP($hBMP, $SearchBMP, $c16RGBPartialMatch)    ;Find needed image
EndFunc   ;==>f_Shots

Func f_SearchBMPArray() ;create array with bmp paths and coordinates
    Local $aSectionNames = IniReadSectionNames(@ScriptDir & "\BMPCoord.ini")
    For $i = 1 To $aSectionNames[0]
        $aBMPCoords[$i][0][0] = $aSectionNames[$i]

        Local $aSectionValues = IniReadSection(@ScriptDir & "\BMPCoord.ini", $aSectionNames[$i])
        For $k = 1 To $aSectionValues[0][0]
            $aBMPCoords[$i][$k][0] = $aSectionValues[$k][0]
            $aBMPCoords[$i][$k][1] = $aSectionValues[$k][1]
EndFunc   ;==>f_SearchBMPArray

Func stop()
    $startFlag = False
    GUICtrlSetState($btnStart, $GUI_ENABLE)
EndFunc   ;==>stop

Func interrupt($hWnd, $Msg, $wParam, $lParam)
    If (BitAND($wParam, 0x0000FFFF) = $btnStop) Or (BitAND($wParam, 0x0000FFFF) = $btnExit) Then
        $startFlag = False
EndFunc   ;==>interrupt

Func _exit()
EndFunc   ;==>_exit



Edited by likehu

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