YippiRips Posted November 1, 2019 Share Posted November 1, 2019 Hello, Can anyone help me, the issue is kinda dumb, but I cannot figure it out. I have been trying to get autoit to draw a line and be able to delete it with another command. I have been googling for 30 minutes now but no answer worked for me. Link to comment Share on other sites More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 I forgot to mention, but I'd also need to know the length of the line once it's drawn. Link to comment Share on other sites More sharing options...
Nine Posted November 1, 2019 Share Posted November 1, 2019 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 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 More sharing options...
Nine Posted November 1, 2019 Share Posted November 1, 2019 8 minutes ago, YippiRips said: the line disappears within miliseconds show the code you got so far... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 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 More sharing options...
Nine Posted November 1, 2019 Share Posted November 1, 2019 you need to have a loop in there after you draw the line. While True Sleep (100) Wend “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 7 minutes ago, Nine said: you need to have a loop in there after you draw the line. While True Sleep (100) Wend https://i.imgur.com/UoPvjpw.gifv You can see on that gif that it doesn't work. Also, I want it so the line disappears after a few lines of code are run successfully. Link to comment Share on other sites More sharing options...
abberration Posted November 1, 2019 Share Posted November 1, 2019 (edited) 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 November 1, 2019 by abberration changed the rounding to 0, since you can't have a fraction of a pixel. Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 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 More sharing options...
junkew Posted November 1, 2019 Share Posted November 1, 2019 Create a borderless window with transparency and draw on it. FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 2 minutes ago, junkew said: Create a borderless window with transparency and draw on it. I'm sorry but can you give me an example of the code, please? Link to comment Share on other sites More sharing options...
Nine Posted November 1, 2019 Share Posted November 1, 2019 #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... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 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 More sharing options...
YippiRips Posted November 1, 2019 Author Share Posted November 1, 2019 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 More sharing options...
Gianni Posted November 1, 2019 Share Posted November 1, 2019 expandcollapse popup#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() Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Nine Posted November 1, 2019 Share Posted November 1, 2019 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... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Gianni Posted November 2, 2019 Share Posted November 2, 2019 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Nine Posted November 2, 2019 Share Posted November 2, 2019 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Gianni Posted November 2, 2019 Share Posted November 2, 2019 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 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now