Jump to content

Drawing a line


Recommended Posts

Very Vague.  Under what situation do you want it ? In your own GUI ?  Over some other application ?  How do you determine the localization ? Etc.

There is multiple way to achieve it.  Depends.

Link to comment
Share on other sites

1 minute ago, Nine said:

Very Vague.  Under what situation do you want it ? In your own GUI ?  Over some other application ?  How do you determine the localization ? Etc.

There is multiple way to achieve it.  Depends.

I want it without a GUI just between two points that I define in the code, the problem with all other code I found online is that the line disappears within miliseconds, but I need it to as long as I want it to last and control how long it will stay up (preferably with another function or something of the sort). And yes, I would want it to be able to overlap another application.

Link to comment
Share on other sites

7 minutes ago, Nine said:

show the code you got so far...

#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $hDC, $hPen, $obj_orig
$hDC = _WinAPI_GetWindowDC(0)
$hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00ff)
$obj_orig = _WinAPI_SelectObject($hDC, $hPen)

_WinAPI_DrawLine($hDC,648, 334,868, 206)

_WinAPI_SelectObject($hDC, $obj_orig)
_WinAPI_DeleteObject($hPen)
_WinAPI_ReleaseDC(0, $hDC)

As soon as you move your mouse accross the line/move the window it's on it disappears. I would like for it to be on the screen for as long as I want it to be, though.

Also, I have no idea of how to measure the length of the line.

Link to comment
Share on other sites

Here is one way to calculate the distance between two points:

$x1 = 340
$y1 = 0
$x2 = 0
$y2 = 600

MsgBox(0, "", "The distance between the to points is: " & _CalcDist($x1, $y1, $x2, $y2) & " pixels.")

Func _CalcDist($x1, $y1, $x2, $y2)
    $xDist = Abs($x2 - $x1)
    $yDist = Abs($y2 - $y1)
    $hyp = Sqrt(($xDist * $xDist) + ($yDist * $yDist))
    Return Round($hyp, 0)
EndFunc

 

Edited by abberration
changed the rounding to 0, since you can't have a fraction of a pixel.
Link to comment
Share on other sites

1 minute ago, abberration said:

Here is one way to calculate the distance between two points:

$x1 = 0
$y1 = 0
$x2 = 340
$y2 = 600

MsgBox(0, "", "The distance between the to points is: " & _CalcDist($x1, $y1, $x2, $y2) & " pixels.")

Func _CalcDist($x1, $y1, $x2, $y2)
    $xDist = Abs($x2 - $x1)
    $yDist = Abs($y2 - $y1)
    $hyp = Sqrt(($xDist * $xDist) + ($yDist * $yDist))
    Return Round($hyp, 2)
EndFunc

 

Do you have any idea how to fix the line issue?

Link to comment
Share on other sites

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hGUI, $hGraphic, $hPen

; Create GUI
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0x00FFFF)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0x00FFFF)

GUISetState(@SW_SHOW)


; Draw line
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 3)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 200, 600, 500, $hPen)

;use ESC key to exit
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

There you go...

Link to comment
Share on other sites

34 minutes ago, Nine said:
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hGUI, $hGraphic, $hPen

; Create GUI
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0x00FFFF)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0x00FFFF)

GUISetState(@SW_SHOW)


; Draw line
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 3)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 200, 600, 500, $hPen)

;use ESC key to exit
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

There you go...

I'm sorry, I know I'm annoying, but 1 last question...
How would I get rid of the line drawn and draw another one at different one at 2 new different points.

Link to comment
Share on other sites

44 minutes ago, Nine said:
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hGUI, $hGraphic, $hPen

; Create GUI
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, $WS_EX_LAYERED)
GUISetBkColor(0x00FFFF)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0x00FFFF)

GUISetState(@SW_SHOW)


; Draw line
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 3)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 200, 600, 500, $hPen)

;use ESC key to exit
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

There you go...

I'm sorry, I know I'm annoying, but 1 last question...
How would I get rid of the line drawn and draw another one at different one at 2 new different points. Also, it is not topmost.

Link to comment
Share on other sites

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Local $hGUI, $hGraphic, $hPen

; Create GUI
$hGUI = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST))
GUISetBkColor(0x00FFFF)
_WinAPI_SetLayeredWindowAttributes($hGUI, 0x00FFFF)

GUISetState(@SW_SHOW)


; Draw line
_GDIPlus_Startup()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 3)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 200, 600, 500, $hPen)

MsgBox(0, '', "To delete that line you could redraw it with the transparent color")
_GDIPlus_PenDispose($hPen)
$hPen = _GDIPlus_PenCreate(0xFF00FFFF, 3)
_GDIPlus_GraphicsDrawLine($hGraphic, 200, 200, 600, 500, $hPen)

MsgBox(0, '', "let's redraw some new lines...")
_GDIPlus_PenDispose($hPen)
$hPen = _GDIPlus_PenCreate(0xFFFF0000, 3)

For $i = 1 To 10
    _GDIPlus_GraphicsDrawLine($hGraphic, Random(0, @DesktopWidth, 1), Random(0, @DesktopHeight, 1), Random(0, @DesktopWidth, 1), Random(0, @DesktopHeight, 1), $hPen)
Next

MsgBox(0, '', "To delete all that lines at once you could erase the whole GUI")
_WinAPI_RedrawWindow($hGUI) ;redraw means erase graphical content in the GUI

MsgBox(0, '', "hit OK to end")

; or use ESC key to exit
; Do
; Until GUIGetMsg() = $GUI_EVENT_CLOSE

; Clean up resources
_GDIPlus_PenDispose($hPen)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

1 hour ago, YippiRips said:

I know I'm annoying

Glad you know it. :) Just kidding.  It is fine.  Sometimes you need a hand to start up.

For now you need to test your own request based on the code we gave you. Taking 10-20 hours of testing without success is normal.  After that if you have no idea where to go, it is time to ask us (show us what you tried, not just say it is not working).  But if you only invest 2-3 hours without even opening help file, well you won't be supported much after awhile.  This community is great, but you need to give in order to get...

Link to comment
Share on other sites

Testing the above example on win10 and win7 it behaves differently:
In windows 10, when you create a "transparent" GUI, like in the above example, you can click on the "transparent" zone of the window, and the click will pass through on, reaching what's below the window, like if there is a real hole.
In Windows 7 instead, if you want the same behaviour, you have to add the "$WS_EX_TRANSPARENT" extended style to the window, otherwisw the click of the mouse will not pass throwgh on, to what's below it, like if there is a glass to stop the cliks.
Well, the drawback of the windows 10 behaviour, is that you have always the "hole" and I've not found a way to let it behave as in windows 7 without the "$WS_EX_TRANSPARENT" extended style, that is don't let clicks pass throwgh the transparency.
Do someone knows how to let windows 10 behave as without the "hole"  on the transparency?

Thanks on advance for any tip

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Hey Chimp,  That is quite strange. Tested it on my Win7 machine and there is no glass that are stopping the clicks.  They go thru no problem.  When I use $WS_EX_TRANSPARENT there is no difference in behavior.

Link to comment
Share on other sites

Thanks Nine, ... I thought computer science was an exact science ... :(
someone else (besides me) experiences the lack of the passing through of the mouse clicks, without the "$WS_EX_TRANSPARENT" extended style on Windows 7?

Thanks

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...