Advertisement
Alan72104

modified

Jan 20th, 2022 (edited)
2,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.01 KB | None | 0 0
  1. #include <GuiConstantsEx.au3>
  2. #include <GDIPlus.au3>
  3. #include <WindowsConstants.au3>
  4. #include <WinAPI.au3>
  5.  
  6. Global $hGUI, $hGraphic, $hPen
  7. Global Const $targetFps = 60
  8. HotKeySet("{F7}", "Terminate")
  9. Opt("MouseCoordMode", 1) ;1=absolute, 0=relative, 2=client
  10. Opt('MustDeclareVars', 1)
  11.  
  12. _Main()
  13.  
  14. Func _Main()
  15.     Local $msg
  16.     Local $timer
  17.    
  18.     Local Const $WS_EX_NOACTIVATE = 0x08000000 ; A top-level window created with this style does not become the foreground window when the user clicks it
  19.     $hGUI = GUICreate("", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_LAYERED, $WS_EX_TRANSPARENT, $WS_EX_NOACTIVATE))
  20.     DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hGUI, "long", 0xEFCDAB , "byte", 255, "long", 0x1 + 0x2)
  21.     ; Since mouse should be passthrough and the window won't be activated, we don't use window event here
  22.     ; GUIRegisterMsg(0xF, "MY_PAINT")
  23.  
  24.     _GDIPlus_Startup()
  25.     $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
  26.  
  27.     $hPen = _GDIPlus_PenCreate(0xFFFF0000, 2)
  28.     ; GDI+ is not hardware accelerated so I personally don't use this, and it messes with the background key 0xABCDEF
  29.     ; _AntiAlias($hGraphic)
  30.    
  31.     GUISetState()
  32.     $timer = TimerInit()
  33.     While 1
  34.         If TimerDiff($timer) >= 1000 / $targetFps Then
  35.             $timer = TimerInit()
  36.             _GDIPlus_GraphicsClear($hGraphic, 0xFFABCDEF)
  37.             _GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth / 2, @DesktopHeight / 2 , MouseGetPos(0), MouseGetPos(1), $hPen)
  38.         EndIf
  39.     WEnd
  40.     Terminate()
  41. EndFunc   ;==>_Main
  42.  
  43. Func _AntiAlias($hGraphics)
  44.     Local $aResult
  45.     $aResult = DllCall($__g_hGDIPDll, "int", "GdipSetSmoothingMode", "hwnd", $hGraphics, "int", 2)
  46.     If @error Then Return SetError(@error, @extended, False)
  47.     Return SetError($aResult[0], 0, $aResult[0] = 0)
  48. EndFunc   ;==>_AntiAlias
  49.  
  50. Func Terminate()
  51.     _GDIPlus_PenDispose($hPen)
  52.     _GDIPlus_GraphicsDispose($hGraphic)
  53.     _GDIPlus_Shutdown()
  54.     Exit
  55. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement