jaberwacky Posted June 13, 2018 Share Posted June 13, 2018 (edited) I started a screen saver years ago, but I got frustrated with it. However, it's now time for me to go through my backlog to finish my scripts. This screensaver is basic but works every pixel over time. I don't know if this is suitable for those prone to seizures with the latest edits. expandcollapse popup#include <GDIPlus.au3> #include <Math.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Const $user32_dll = DllOpen("User32.dll") Const $mouse_proc_callback = DllCallbackRegister(_mouse_proc, "long", "int;wparam;lparam;") Const $mouse_hook = _create_mouse_hook($WH_MOUSE_LL) Const $dw = @DesktopWidth Const $dh = @DesktopHeight Const $hGUI = GUICreate("Circle Screen Saver", $dw, $dh, 0, 0, $WS_POPUP) _GDIPlus_Startup() Const $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Example() Func Example() GUISetState(@SW_SHOWNORMAL) Local $x, $y, $color, $maximum_diameter, $step_size Do $x = Random(10, $dw - 10, 1) $y = Random(10, $dh - 10, 1) $color = _random_color() $maximum_diameter = _maximum_diameter($x, $y) _GDIPlus_GraphicsClear($hGraphic, $color) $step_size = Random(1, 4, 1) ; suggested by junkew For $i = 0 To $maximum_diameter Step $step_size _draw_circle($x, $y, $i, _random_color()) Next _GDIPlus_GraphicsClear($hGraphic, $color) For $i = $maximum_diameter To 0 Step -$step_size _draw_circle($x, $y, $i, _random_color()) Next Until GUIGetMsg() = $GUI_EVENT_CLOSE _exit() EndFunc ;==>Example Func _mouse_proc($code, $w_param, $l_param) Switch $code >= 0 Case True Switch $w_param Case $WM_MOUSEMOVE _exit() EndSwitch EndSwitch Return DllCall($user32_dll, "lresult", "CallNextHookEx", "handle", $mouse_hook, "int", $code, "wparam", $w_param, "lparam", $l_param)[0] EndFunc ;==>_mouse_proc Func _create_mouse_hook(Const $hook) ; _WinAPI_SetWindowsHookEx Local Const $aResult = DllCall($user32_dll, "handle", "SetWindowsHookEx", _ "int", $hook, _ "ptr", DllCallbackGetPtr($mouse_proc_callback), _ "handle", DllCall("kernel32.dll", "handle", "GetModuleHandleW", "wstr", 0), _ "dword", 0)[0] Return @error ? SetError(@error, @extended, 0) : $aResult EndFunc ;==>_create_mouse_hook Func _draw_circle(Const $x, Const $y, Const $diameter, Const $color) ; modified by UEZ Local Const $hPen = _GDIPlus_PenCreate($color, 3) _GDIPlus_GraphicsDrawArc($hGraphic, $x - ($diameter / 2), $y - ($diameter / 2), $diameter, $diameter, 180, 360, $hPen) _GDIPlus_PenDispose($hPen) ; add this line otherwise memory leak because pen handle will be created everytime when function is called with disposing it! EndFunc ;==>_draw_circle Func _maximum_diameter(Const $x, Const $y) Local Const $half_width = $dw / 2 Local Const $half_height = $dh / 2 Select Case $x < $half_width Select Case $y < $half_height Return _Min($x, $y) * 2 Case $y >= $half_height Return _Min($x, $dh - $y) * 2 EndSelect Case $x >= $half_width Select Case $y < $half_height Return _Min($y, $dw - $x) * 2 Case $y >= $half_height Return _Min($dw - $x, $dh - $y) * 2 EndSelect EndSelect EndFunc ;==>_maximum_diameter Func _random_color() Return "0xFF" & Hex(Random(0, 255, 1) & Random(0, 255, 1) & Random(0, 255, 1), 6) EndFunc ;==>_random_color Func _exit() DllCall($user32_dll, "bool", "UnhookWindowsHookEx", "handle", $mouse_hook) DllCallbackFree($mouse_proc_callback) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() Exit EndFunc ;==>_exit Edited June 17, 2018 by jaberwacky Suggested edits from respected forum members. aa2zz6 1 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
aa2zz6 Posted June 13, 2018 Share Posted June 13, 2018 That's really neat. Thanks for sharing jaberwacky 1 Link to comment Share on other sites More sharing options...
junkew Posted June 13, 2018 Share Posted June 13, 2018 nice not sure why there is a msgbox in it This one gives also fun Local Const $hPen = _GDIPlus_PenCreate($color, 3,3) add Step random and use it in the for loop step +/- $stepsize $stepSize=random(1,4,1) jaberwacky 1 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...
UEZ Posted June 13, 2018 Share Posted June 13, 2018 @jaberwacky: your script has a memory leak in function _draw_circle. Must be Func _draw_circle(Const $hGraphic, Const $x, Const $y, Const $diameter, Const $color) Local Const $hPen = _GDIPlus_PenCreate($color, 3) _GDIPlus_GraphicsDrawArc($hGraphic, $x - ($diameter / 2), $y - ($diameter / 2), $diameter, $diameter, 180, 360, $hPen) _GDIPlus_PenDispose($hPen) ;add this line otherwise memory leak because pen handle will be created everytime when function is called with disposing it! EndFunc jaberwacky 1 Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
jaberwacky Posted June 17, 2018 Author Share Posted June 17, 2018 (edited) Thanks for the interest! I forgot I posted this, lol. I edited the first post with the latest code! Also added code to exit when the mouse is moved like a normal screen saver. Thinking about a way to make every circle grow at the same speed regardless of diameter. Edited June 17, 2018 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? 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