Sign in to follow this  
Followers 0
faustf

draw line point to point

5 posts in this topic

hi guy i have a scripted i wanna draw line point A to point B .

for indicate point A use dx mouse button, after sign point B ,and after the script draw a line but dont draw correctly

While 1
Select
Case _IsPressed(02) And $c_td=0
   $pos = MouseGetPos()
   $b = GUICtrlCreateGraphic(($pos[0]-50), ($pos[1]-30), 81, 20)
    GuiCtrlSetState(-1,$GUI_ONTOP)
    GUICtrlSetBkColor(-1, 0xff00)
   $Label2 = GUICtrlCreateLabel($tag_scritta, ($pos[0]-50), ($pos[1]-30), 81, 20)
   GUICtrlSetBkColor(-1, 0x00FF00)
   MsgBox(4160+48,"info","Inserisci punto di arrivo")
   $c_td=$c_td+1
MsgBox(0,'',$pos[0]&'  '&$pos[1])
Case _IsPressed(02) And $c_td<>0
   $pos1 = MouseGetPos()
   $z = GUICtrlCreateGraphic(($pos1[0]-5), ($pos1[1]-20), 7, 7)
   ; GUICtrlSetGraphic(-1, $GUI_GR_LINE, ($pos[0]-50), ($pos[0]-5))
   GuiCtrlSetState(-1,$GUI_ONTOP)
    GUICtrlSetBkColor(-1, 0xff00)
   ; $j = GUICtrlCreateGraphic(-1, $GUI_GR_LINE,($pos[0]), ($pos[1]), ($pos[1]))
   ; GUICtrlSetGraphic(-1, $GUI_GR_LINE, ($pos[0]-50), ($pos[0]-5))


  _GDIPlus_Startup()
   $hGraphic=_GDIPlus_GraphicsCreateFromHWND($hGUI)
  _GDIPlus_GraphicsDrawLine ($hGraphic, ($pos[0]-50), ($pos[1]-30), ($pos1[0]-5), ($pos1[1]-20))
  _GDIPlus_GraphicsDispose($hGraphic)
  _GDIPlus_Shutdown()

MsgBox(0,'',$pos[0]&'  '&$pos[1])
   $c_td=0
   ExitLoop
EndSelect

WEnd

Share this post


Link to post
Share on other sites



Hi.

The point you missed is the fact, that "MouseGetPos()" will return "Screen related coords", but what you need is "window related coords".

Move your window to the upper left corner of your screen, you'll see, what I mean.

still buggy script, but at least it's executable:

#include <GUIConstantsEx.au3>
#Include <GDIPlus.au3>
#Include <Misc.au3>


$c_td = 0
$tag_scritta="some text"
$w=500
$h=500
$hGUI=GUICreate("hGUI",$w,$h)
GUISetState()

While 1
    Select
        Case _IsPressed(02) And $c_td = 0
            $posA = MouseGetPos()
            $b = GUICtrlCreateGraphic(($posA[0] - 50), ($posA[1] - 30), 81, 20)
            GUICtrlSetState(-1, $GUI_ONTOP)
            GUICtrlSetBkColor(-1, 0xff00)
            $Label2 = GUICtrlCreateLabel($tag_scritta, 30, 30, 100, 100)
            ; $Label2 = GUICtrlCreateLabel($tag_scritta, ($posA[0] - 50), ($posA[1] - 30), 81, 20)
            GUICtrlSetBkColor(-1, 0x00FF00)
            MsgBox(0, "first click",$posA[0] & " - " & $posA[1],5)
            $c_td = 1
        Case _IsPressed(02) And $c_td <> 0
            $posB = MouseGetPos()
            $z = GUICtrlCreateGraphic(($posB[0] - 5), ($posB[1] - 20), 7, 7)
            GUICtrlSetState(-1, $GUI_ONTOP)
            GUICtrlSetBkColor(-1, 0xff00)
            _GDIPlus_Startup()
            $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
            _GDIPlus_GraphicsDrawLine($hGraphic, ($posA[0] - 50), ($posA[1] - 30), ($posB[0] - 5), ($posB[1] - 20))
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            MsgBox(0, '', $posA[0] & '  ' & $posA[1],5)
            $c_td = 0
    EndSelect

WEnd

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites

i try this script but dont trace black line

Share this post


Link to post
Share on other sites

and how can i find a correct coordinate ??

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

and how can i find a correct coordinate ??

By setting "Opt("MouseCoordMode", 2)" which returns the mouse coordinates relative to the client area of the active window.

#include <GDIPlus.au3>
#include <Misc.au3>

Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

Local $posA, $posB, $b, $z
Local $w = 500
Local $h = 500
Local $hGUI = GUICreate("hGUI ()", $w, $h)

GUICtrlCreateLabel("Drag mouse while right mouse button held down." & @CRLF & _
"Drag mouse while right mouse button and Alt key are held down.", 10, 10, 400, 60)
GUISetState()

While 1
$msg = GUIGetMsg()
Select
Case $msg = -3
Exit
Case _IsPressed('02') And _IsPressed('12') ; Press right mouse button + Alt key
$posA = MouseGetPos()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xff0000ff)
While _IsPressed('02')
$posB = MouseGetPos()
_GDIPlus_GraphicsDrawLine($hGraphic, ($posA[0]), ($posA[1]), ($posB[0]), ($posB[1]), $hPen)
WEnd
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Case _IsPressed('02')
$posA = MouseGetPos()
While _IsPressed('02')
WEnd
$posB = MouseGetPos()
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xffff0000, 3)
_GDIPlus_GraphicsDrawLine($hGraphic, ($posA[0]), ($posA[1]), ($posB[0]), ($posB[1]), $hPen)
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
EndSelect
WEnd

Edit: Added all below. Ability to save graphics.

An example save:-

Posted Image

#include <GDIPlus.au3>
#include <Misc.au3>

Opt("MouseCoordMode", 2) ;1=absolute, 0=relative, 2=client

Local $posA, $posB, $b, $z
Local $w = 500
Local $h = 500
Local $hGUI = GUICreate("hGUI", $w, $h)

GUICtrlCreateLabel("Drag mouse while right mouse button held down;" & @CRLF & _
        "Drag mouse while right mouse button and Alt key are held down; or, " & @CRLF & _
        "Press Ctrl + C to copy graphics to a file.", 10, 10, 400, 60)
_GDIPlus_Startup()
Local $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($w, $h, $hGraphicGUI)
$hGraphic = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsClear($hGraphic, 0xFFFFFFFF)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = -3
            _WinAPI_DeleteObject($hBitmap)
            _GDIPlus_GraphicsDispose($hGraphicGUI)
            _GDIPlus_GraphicsDispose($hGraphic)
            _GDIPlus_Shutdown()
            Exit
        Case _IsPressed('02') And _IsPressed('12') ; Press right mouse button + Alt key
            $posA = MouseGetPos()
            $hPen = _GDIPlus_PenCreate(0xff0000ff)
            While _IsPressed('02')
                $posB = MouseGetPos()
                _GDIPlus_GraphicsDrawLine($hGraphic, ($posA[0]), ($posA[1]), ($posB[0]), ($posB[1]), $hPen)
                _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBitmap, 0, 0)
            WEnd
            _GDIPlus_PenDispose($hPen)
        Case _IsPressed('02')
            $posA = MouseGetPos()
            While _IsPressed('02')
            WEnd
            $posB = MouseGetPos()
            $hPen = _GDIPlus_PenCreate(0xffff0000, 3)
            _GDIPlus_GraphicsDrawLine($hGraphic, ($posA[0]), ($posA[1]), ($posB[0]), ($posB[1]), $hPen)
            _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBitmap, 0, 0)
            _GDIPlus_PenDispose($hPen)
        Case _IsPressed('11') And _IsPressed('43') ; Press Ctrl + C keys to save graphics to "TestGdi.bmp" file
            While _IsPressed('11') And _IsPressed('43'); While loop is to prevent multiple key presses.
            WEnd
            _GDIPlus_ImageSaveToFile($hBitmap, "TestGdi.bmp")
            ShellExecute("TestGdi.bmp")
    EndSelect
WEnd
Edited by Malkey

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