Sign in to follow this  
Followers 0
Kyler Carlson

Draw Lines in a Gui Between Points

6 posts in this topic

#1 ·  Posted (edited)

ok. Basically I need a script that can draw a straight line between two points in this gui. Basically, you press "Z", a green dot shows up. Then you press "Z" again and a new dot pops up with a line between the two of them. If anybody has a way to save the coordinates ($x and $y) in a file but have them be called x1, y1 and then x2, y2 in an .ini file that would be very helpful. If there is a better way to do what I did in my script below, please help.

#include <GUIConstants.au3>


GUICreate("   WÌÑÑÒVÅTÍÓÑ -- P§   ",800,600)
$reset = GUICtrlCreateButton("Reset",50,20,50,30)
$save = GUICtrlCreateButton("Save",375,20,50,30)
$exit = GUICtrlCreateButton("Exit",700,20,50,30)
GUICtrlCreatePic("C:\Documents and Settings\HP_Administrator\Desktop\field.bmp",50,70,714,308)
GUISetState()
While 1
    $dll = DllOpen("user32.dll")
        If _IsPressed("5A", $dll) Then
            waypoint()
        Else
            sleep(20)
        EndIf
    DllClose($dll)
    Sleep(5)
    $msg = GUIGetMsg()
    If $msg = $reset Then reset()
    If $msg = $save then save()
    If $msg = $exit then exit1()
    If $msg = $GUI_EVENT_CLOSE Then exit1()
WEnd
    
    
Func reset()
    GUICtrlCreatePic("C:\Documents and Settings\HP_Administrator\Desktop\field.bmp",50,70,714,308)
    GUICtrlCreatePic("C:\Documents and Settings\HP_Administrator\Desktop\field.bmp",50,70,714,308)
EndFunc

Func save()
EndFunc

Func exit1()
    Exit
EndFunc

Func waypoint()
    $win = WinGetPos("   WÌÑÑÒVÅTÍÓÑ -- P§   ")
    $off_x = $win[0]
    $off_y = $win[1]
    $pos = MouseGetPos()
    $x = $pos[0] - 8 - $off_x
    $y = $pos[1] - 27 - $off_y
;MsgBox(0,"",$off_x & "   " & $off_y & "   " & $x & "   " & $y)
    GUICtrlCreatePic("C:\Documents and Settings\HP_Administrator\Desktop\dot.bmp",$x,$y,9,9)
    
EndFunc

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

Thanks in advance.

Edit: this needs to work more than 2 times by the way so it needs to be able to repeat basically up to 1000 times (random high number).

Edited by Kyler Carlson

Share this post


Link to post
Share on other sites



Okay the code below works and is exactle what I want except for one thing. I want to lines to stay on the gui, even after it is minimized or a window is put above it. If anyone knows of a way to make the lines be perminant, Your help would be great. Also, I have already asked JdeB but he didn't know a good way to do it and said to ask the community.

; Draw a line on any Screen/Program
; Author JdeB, Co-Author Valuater

Dim $Mpos_1 = "", $Mpos_1A = "", $Mpos_2 = "", $Mpos_2A = "", $line = ""
$LineColor = 0x0000ff; color BGR
$LineWidth = 10

HotKeySet( "{ESC}", "Get_Exit")
HotKeySet("{F1}", "Get_pos_one")
HotKeySet("{F2}", "Get_pos_two")
HotKeySet( "{F3}", "Get_drawing")

MsgBox(0, "User Info", "Press *ESC* to exit" & @CRLF & "Press *F1* to set First position" & @CRLF & "Press *F2* to set Second position" & @CRLF & "Press *F3* to Draw the Line")

While 1
    Sleep(100)
WEnd

Func Get_pos_one()
    GUICtrlDelete($line)
    $Ms_In = MouseGetPos()
    $Mpos_1 = $Ms_In[0]
    $Mpos_2 = $Ms_In[1]
    
EndFunc ;==>Get_pos_one

Func Get_pos_two()
    GUICtrlDelete($line)
    $Ms_In2 = MouseGetPos()
    $Mpos_1A = $Ms_In2[0]
    $Mpos_2A = $Ms_In2[1]
    
EndFunc ;==>Get_pos_two

Func Get_drawing()
    
    If $Mpos_1 = "" Or $Mpos_1A = "" Then
        MsgBox(0, "Draw Error", " Two points of reference are required")
        MsgBox(0, "User Info", "Press *ESC* to exit" & @CRLF & "Press *F1* to set First position" & @CRLF & "Press *F2* to set Second position" & @CRLF & "Press *F3* to Draw the Line")
        Return
    EndIf
    $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0)
    $pen = DllCall("gdi32.dll", "int", "CreatePen", "int", 0, "int", $LineWidth, "int", $LineColor)
    DllCall("gdi32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0])
    DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_1, "int", $Mpos_2, "int", 0)
    DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_1A, "int", $Mpos_2A)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0])
    
EndFunc ;==>Get_drawing

Func Get_Exit()
    Exit
EndFunc ;==>Get_Exit

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Okay the code below works and is exactle what I want except for one thing. I want to lines to stay on the gui, even after it is minimized or a window is put above it. If anyone knows of a way to make the lines be perminant, Your help would be great. Also, I have already asked JdeB but he didn't know a good way to do it and said to ask the community.

You need to put your drawings into some function which must me hooked to WM_PAINT message (by GuiRegisterMsg).

See BlackJack cards game ...

Edited by Zedna

Share this post


Link to post
Share on other sites

Zedna... I'm kindda a noob with programing and what you are saying makes... well no sense to me. Can you either reword it or write code that does what you just said?

is GUIRegisterMsg($WM_PAINT, 'MY_WM_PAINT') what you are talking about and if so, how do i use that? thanks.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Zedna... I'm kindda a noob with programing and what you are saying makes... well no sense to me. Can you either reword it or write code that does what you just said?

Hey man I will not provide you teaching of AutoIt :nuke:

I can only help you with some specific (not general) questions.

Just look into great AutoIt Helpfile (with examples) and if it's not enough for you then search for more in this forum. Here are plenty of usable code pieces!

But as NOOB (as you said) you shouldn't go into such advanced scripts.

Instead start with some simpler scripts and lately as you will get more experienced in AutoIt you could do also such more complicated scripting/programming :P

is GUIRegisterMsg($WM_PAINT, 'MY_WM_PAINT') what you are talking about and if so, how do i use that? thanks.

Yes it's exactly what I meant.

Edited by Zedna

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