Jump to content
Sign in to follow this  
fenhanxue

GUICtrlCreateGraphic ,how to draw a line which will follow mouse movement

Recommended Posts

fenhanxue

i need to draw a line form position 0 ($x_0,$y_0 )   to  position 1 ($x_1,$y_1 ) 

i will click left mouse 2 times

position_0 is the mouse pos where i first click left mouse

position_1 is the mouse pos where i click left mouse again

and between the 2 clicks, i want to draw a line start form position_0 to where my mouse moved to .

 

#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>
Opt("MouseCoordMode", 2)
$hGUI = GUICreate("Draw a line",400,400)
$g = GUICtrlCreateGraphic(0, 0, 400, 400)
GUICtrlSetBkColor($g, 0xCCFFCC)

GUISetState()



;1  first,i moved mouse to position($x_0,$y_0),click mouse left
Do
Until _IsPressed('01')
Local $temp = MouseGetPos()
Local $x_0 = $temp[0]
Local $y_0 = $temp[1]
Sleep(500)


;2  then ,I will move mouse to a random position ($x_r ,$y_r)
    ;=====   how to show a line form $x_0,$y_0  to $x_r ,$y_r ????
    ;once i move the mouse ,the line should be redrawed immediately


;3  finally, i click mouse left in position ($x_1,$y_1),there should be only one line form $x_0,$y_0 to $x_1,$y_1
Do
Until _IsPressed('01')
ConsoleWrite('2')

Local $temp = MouseGetPos()
Local $x_1 = $temp[0]
Local $y_1 = $temp[1]


GUICtrlSetGraphic($g,$GUI_GR_MOVE,$x_0,$y_0)
GUICtrlSetGraphic($g,$GUI_GR_LINE,$x_1,$y_1)
_WinAPI_RedrawWindow($hGUI)
Sleep(5000)

 

 

Edited by fenhanxue

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.