HankHell Posted February 3, 2018 Share Posted February 3, 2018 heya guys, just messing around with some scripts and thought this one was kinda fun. it will allow you to draw on your desktop background. you have a selection of 3 colors. Hold F1 to draw, press F2 to open color menu. ESC to close the program. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> HotKeySet("{F1}", "SetPixel") ;hold F1 to draw HotKeySet("{F2}", "ShowGUI") ;press F2 to open color menu HotKeySet("{ESC}", "End") ;ESC to close the program Global $BrushColor = 0x00FF00 Global $BrushWidth = 6 Global $Mpos_1 = "" Global $Mpos_2 = "" Global $Form1 = GUICreate("Colors", 149, 51, -1, -1) Global $Blue = GUICtrlCreateButton("ColorBlue", 0, 0, 75, 25) Global $Green = GUICtrlCreateButton("ColorGreen", 72, 0, 75, 25) Global $Red = GUICtrlCreateButton("ColorRed", 40, 24, 75, 25) GUISetState(@SW_SHOW) Global $State = 1 GUI() Func GUI() While $State = 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Blue ColorBlue() Case $Green ColorGreen() Case $Red ColorRed() EndSwitch WEnd EndFunc Func SetPixel() $Mpos = MouseGetPos() $Mpos_x = $Mpos[0] $Mpos_y = $Mpos[1] $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0) $pen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $BrushWidth, "int", $BrushColor) DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0]) DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y, "int", 0) DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0]) $Mpos_x = 0 $Mpos_y = 0 $Mpos = 0 EndFunc Func ColorRed() $BrushColor = 0x0000FF Sleep(50) GUISetState(@SW_HIDE) EndFunc Func ColorGreen() $BrushColor = 0x00FF00 Sleep(50) GUISetState(@SW_HIDE) EndFunc Func ColorBlue() $BrushColor = 0xFF0000 Sleep(50) GUISetState(@SW_HIDE) EndFunc Func ShowGUI() GUISetState(@SW_SHOW) EndFunc Func End() Exit EndFunc Link to comment Share on other sites More sharing options...
taurus905 Posted March 28, 2018 Share Posted March 28, 2018 Hello HankHell, That's a cool little script. I was trying to figure out how to modify it to draw a straight line between two points. taurus905 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs Link to comment Share on other sites More sharing options...
Bilgus Posted March 28, 2018 Share Posted March 28, 2018 Couple things to note in that script, You are suppose to store the old object when you use selectobject and restore it when done You are then suppose to delete that new object when you are done with it If you don't you will eventually run out of gdi objects You should look at the helpfile about all these calls you are doing with DLLCALL The udf WinAPI.au3 makes them much easier to use and explains some of the gotchas F3 sets a point & draws a dot move your mouse and press F3 again and a line is drawn expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> HotKeySet("{F1}", SetPixel) ;hold F1 to draw HotKeySet("{F2}", ShowGUI) ;press F2 to open color menu HotKeySet("{F3}", SetPoint) ;Press F3 to Set a point press again to draw line to new point HotKeySet("{ESC}", "End") ;ESC to close the program Global $BrushColor = 0x00FF00 Global $BrushWidth = 6 Global $Mpos_1 = "" Global $Mpos_2 = "" Global $Form1 = GUICreate("Colors", 149, 51, -1, -1) Global $Blue = GUICtrlCreateButton("ColorBlue", 0, 0, 75, 25) Global $Green = GUICtrlCreateButton("ColorGreen", 72, 0, 75, 25) Global $Red = GUICtrlCreateButton("ColorRed", 40, 24, 75, 25) GUISetState(@SW_SHOW) Global $State = 1 GUI() Func GUI() While $State = 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Blue ColorBlue() Case $Green ColorGreen() Case $Red ColorRed() EndSwitch WEnd EndFunc Func SetPixel() $Mpos = MouseGetPos() $Mpos_x = $Mpos[0] $Mpos_y = $Mpos[1] $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0) $pen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $BrushWidth, "int", $BrushColor) $old_pen = DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0]) DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y, "int", 0) DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y) DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $old_pen[0]) ;Need to select original object back into DC DllCall("GDI32.dll", "int", "DeleteObject", "int", $pen[0]) ;Need To delete the created object DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0]) $Mpos_x = 0 $Mpos_y = 0 $Mpos = 0 EndFunc Func SetPoint() Static $LastMpos_x = -1 Static $LastMpos_y = -1 $Mpos = MouseGetPos() $Mpos_x = $Mpos[0] $Mpos_y = $Mpos[1] If $LastMpos_x <> -1 And $LastMpos_y <> -1 Then $hd = DllCall("user32.dll", "int", "GetDC", "hwnd", 0) $pen = DllCall("GDI32.dll", "int", "CreatePen", "int", 0, "int", $BrushWidth, "int", $BrushColor) $old_pen = DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $pen[0]) DllCall("GDI32.dll", "int", "MoveToEx", "hwnd", $hd[0], "int", $LastMpos_x, "int", $LastMpos_y, "int", 0) DllCall("GDI32.dll", "int", "LineTo", "hwnd", $hd[0], "int", $Mpos_x, "int", $Mpos_y) DllCall("GDI32.dll", "int", "SelectObject", "int", $hd[0], "int", $old_pen[0]) ;Need to select original object back into DC DllCall("GDI32.dll", "int", "DeleteObject", "int", $pen[0]) ;Need To delete the created object DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $hd[0]) $LastMpos_x = -1 $LastMpos_y = -1 Else SetPixel() $LastMpos_x = $Mpos_x $LastMpos_y = $Mpos_y EndIf $Mpos_x = 0 $Mpos_y = 0 $Mpos = 0 EndFunc Func ColorRed() $BrushColor = 0x0000FF Sleep(50) GUISetState(@SW_HIDE) EndFunc Func ColorGreen() $BrushColor = 0x00FF00 Sleep(50) GUISetState(@SW_HIDE) EndFunc Func ColorBlue() $BrushColor = 0xFF0000 Sleep(50) GUISetState(@SW_HIDE) EndFunc Func ShowGUI() GUISetState(@SW_SHOW) EndFunc Func End() Exit EndFunc Link to comment Share on other sites More sharing options...
taurus905 Posted April 7, 2018 Share Posted April 7, 2018 Hello Bilgus, Thank you for the tips on using gdi objects and providing a great example. This simple script will be very useful for me. I appreciate your experience and willingness to share. taurus905 Bilgus 1 "Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs 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