Jump to content
Sign in to follow this  
exevan

Problem with function and winapi

Recommended Posts

Hello, so i use this function:

Func Pixel_Distance($x1, $y1, $x2, $y2)
    If $x2 = $x1 And $y2 = $y1 Then
        Return 0
    Else
        $a = $y2 - $y1
        $b = $x2 - $x1
        $c = Sqrt($a * $a + $b * $b)
        Return $c
    EndIf
EndFunc
Func DrawLine($start_x, $start_y, $end_x, $end_y, $color)
    Global $hDC, $hPen, $obj_orig
    $hDC = _WinAPI_GetWindowDC(0)
    $hPen = _WinAPI_CreatePen($PS_SOLID, 1, $color)
    $obj_orig = _WinAPI_SelectObject($hDC, $hPen)
    _WinAPI_DrawLine($hDC, $start_x, $start_y, $end_x, $end_y)
    _WinAPI_RedrawWindow(_WinAPI_GetDesktopWindow(), 0, 0, $RDW_INVALIDATE + $RDW_ALLCHILDREN)
EndFunc
Func _Test()
    while 1
        Local $FirstFile = PixelSearch(389, 76,1540, 870,0xF6F2D9)
        Local $SecondFile = PixelSearch(389, 76,1540, 870,0xDA7714)
        if not @error then

            Pixel_Distance($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1])
            DrawLine($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1], 0x00)
            _WinAPI_SelectObject($hDC, $obj_orig)
            _WinAPI_DeleteObject($hPen)
            _WinAPI_ReleaseDC(0, $hDC)  
            ToolTip("Distance: "&$c,0,0)
            sleep(1000)
        else
            ContinueLoop
        endif
    wend
EndFunc 

After 15 or 20 seconds i've got a error:

Pixel_Distance($FirstFile[0],...)
               $FirstFile ^ ERROR
Error: Subscrit used on non accesible variable

What's wrong?

And next question is about WinApi

My function draw a line on desktop every one second. How can i delete last line before a new line is draw?

Edited by exevan

Share this post


Link to post
Share on other sites

So what i must do when the pixelsearch is failed? i try this:

Func _Test()
    while 1
        Local $FirstFile = PixelSearch(389, 76,1540, 870,0xF6F2D9)
        Local $SecondFile = PixelSearch(389, 76,1540, 870,0xDA7714)
        if not @error then

            Pixel_Distance($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1])
            DrawLine($FirstFile[0], $FirstFile[1], $SecondFile[0],$SecondFile[1], 0x00)
            _WinAPI_SelectObject($hDC, $obj_orig)
            _WinAPI_DeleteObject($hPen)
            _WinAPI_ReleaseDC(0, $hDC)  
            ToolTip("Distance: "&$c,0,0)
            sleep(1000)
        else
            _Test()
        endif
    wend
EndFunc

but doesn't work;/

Share this post


Link to post
Share on other sites

This 

if not @error then

Needs to changed to test that both $firstfile and $secondfile are arrays (IsArray() function).

You can leave continueloop and get shut of recursive _Test()


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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