Sign in to follow this  
Followers 0
XZ3R0

Targeting Frame

3 posts in this topic

I want to make a frame appear when running a script. I want 4 red lines to make a box, or frame. Can anyone point me in the right direction?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here's a modified version of something I threw together a little while back. It has more than you need but maybe you can learn more from it. :)

Click and Drag to select a region on the screen. It will display co-ordinate info as you drag. When you release the mouse button it will draw a red box in the region you selected. I recommend just learning from this cause I don't like it very much. It leaves trails if windows move beneath it. There may be a way to avoid/fix that, but it's beyond my knowledge.

$region = _GetMouseRegion() ;Captures Region as Array ([0][0-1]=Start X&Y  [1][0-1]=End X&Y  [2][0-1]=Distance Between

While 1
    Dim $start[2]
    $start[0] = $region[0][0]
    $start[1] = $region[0][1]
    Dim $current[2]
    $current[0] = $region[1][0]
    $current[1] = $region[1][1]
    _ShowRegionHighlight($start,$current)
Wend

Func _StartDrag($dll)
    Do
        sleep(10)
    Until _IsPressed(1,$dll)
    Return MouseGetPos()
EndFunc

Func _FinishDrag($dll,$start,$flags=3)
    While _IsPressed(1,$dll)
        $current = MouseGetPos()
        If BitOR($flags,1) = $flags Then _ShowRegionStats($start,$current)
    WEnd
    ToolTip("")
    Return MouseGetPos()
EndFunc

Func _GetMouseRegion()
    $dll = DllOpen("user32.dll")
    $start = _StartDrag($dll)
    $finish = _FinishDrag($dll,$start)
    DllClose($dll)
    Dim $box[3][2]
    For $i = 0 to 2
        For $x = 0 to 1
            If $i = 0 Then
                $box[$i][$x] = $start[$x]
            ElseIf $i = 1 Then
                $box[$i][$x] = $finish[$x]
            Else
                $box[$i][$x] = $finish[$x] - $start[$x]
            EndIf
        Next
    Next
    Return $box
EndFunc

Func _ShowRegionStats($start,$current)
    If $start[0] > $current[0] And $start[1] <> $current[1] Then
        ToolTip("X:" & $start[0] & @TAB & "X:" & $current[0] & @CRLF & "Y:" & $start[1] & @TAB & "Y:" & $current[1] & @CRLF & @CRLF & "Width = " & Abs($current[0]-$start[0]) & @CRLF & "Height = " & Abs($current[1]-$start[1]),$current[0]-74,$current[1]-70)
    ElseIf $start[0] < $current[0] And $start[1] <> $current[1] Then
        ToolTip("X:" & $start[0] & @TAB & "X:" & $current[0] & @CRLF & "Y:" & $start[1] & @TAB & "Y:" & $current[1] & @CRLF & @CRLF & "Width = " & Abs($current[0]-$start[0]) & @CRLF & "Height = " & Abs($current[1]-$start[1]),$current[0],$current[1])
    EndIf
EndFunc

Func _ShowRegionHighlight($start,$current)
    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", 1, "int", 0x0000ff)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
    ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $current[1])
    ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $current[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])

    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])

    sleep(50)
EndFunc

Func _IsPressed($sHexKey, $vDLL = 'user32.dll')
    Local $a_R = DllCall($vDLL, "int", "GetAsyncKeyState", "int", '0x' & $sHexKey)
    If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
    Return 0
EndFunc

edit: There are easier methods if you want to draw it within an AutoIt GUI.

Search the help file for GUICtrlCreateGroup, and _GDIPlus_GraphicsDrawRect

Edited by spudw2k

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

cool thx. my favorite way is to learn from more complicated stuff.

edit: so i made this

Dim $start[2]
    $start[0] = 475
    $start[1] = 280
Dim $current[2]
    $current[0] = 1030
    $current[1] = 630


Func targetframe($start,$current)
    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", 1, "int", 0x0000ff)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
 ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $current[1])
 ;DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $start[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$current[0], "int", $current[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $start[0], "int", $current[1])
   
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int",$start[0], "int", $start[1], "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $current[0], "int", $start[1])

    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])

    sleep(50)
EndFunc

but once you move something on the screen the box disappears. how can i made it so it will stay for a set amount of time?

Edited by XZ3R0

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  
Followers 0