yuser

Drawing on screen

3 posts in this topic

#1 ·  Posted (edited)

Hi there everyone, the thing is i've been trying to find a proper script for drawing on the screen. But what i mean is like paint on the screen without having a gui. What i saw so far was UEZ's code.

#Include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()

Global Const $HBITMAP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, 0)

Global Const $hGUI = GUICreate("Mark screen by UEZ", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetState(@SW_SHOW, $hGUI)

Global Const $hGraphic_Bg = _GDIPlus_GraphicsCreateFromHWND($hGUI)
Global Const $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($HBITMAP)
_GDIPlus_GraphicsDrawImage($hGraphic_Bg, $hBmp, 0, 0)
_WinAPI_DeleteObject($HBITMAP)

Global Const $pen_size = 8
Global Const $hPen = _GDIPlus_PenCreate(0xff000000, $pen_size)

GUISetOnEvent(-3, "_Exit")
OnAutoItExitRegister("_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)

Global Const $om = MouseGetCursor()

While Sleep(100000)
WEnd

Func Draw()
    Local $aMC, $mxo, $myo
    $aMC = GUIGetCursorInfo($hGUI)
    Sleep(50)
    Do
        GUISetCursor(0, 1, $hGUI)
        $mxo = $aMC[0]
        $myo = $aMC[1]
        $aMC = GUIGetCursorInfo($hGUI)
        If $mxo <> $aMC[0] Or $myo <> $aMC[1] Then
            _GDIPlus_GraphicsDrawLine($hGraphic_Bg, $aMC[0], $aMC[1], $mxo, $myo, $hPen)
            $mxo = $aMC[0]
            $myo = $aMC[1]
        EndIf
    Until Not $aMC[2]
EndFunc

Func _Exit()
    GUISetCursor($om, 1, $hGUI)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_GraphicsDispose($hGraphic_Bg)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc

This works pretty okay except the smoothness of the pen which looks awful when you use :/

I either need to smoothen the pen on this script or ask for another.

I appreciate your help in advance :^)

Edited by yuser

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Here a little modified version from the code above:

#Include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()

Global Const $HBITMAP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, 0)

Global Const $hGUI = GUICreate("Draw on bitmap by UEZ", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetState(@SW_SHOW, $hGUI)

Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
_GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, 4)

Global Const $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($HBITMAP)
_GDIPlus_GraphicsDrawImage($hCanvas, $hBmp, 0, 0)

Global Const $hPen = _GDIPlus_PenCreate(0xFFFF0000, 16)
_GDIPlus_PenSetLineJoin($hPen, 2)
Global Const $hPath = _GDIPlus_PathCreate()

GUISetOnEvent(-3, "_Exit")
OnAutoItExitRegister("_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)

Global Const $om = MouseGetCursor()

While Sleep(100000)
WEnd

Func Draw()
    Local $aMC = GUIGetCursorInfo($hGUI)
    While Sleep(10) * $aMC[2]
        GUISetCursor(0, 1, $hGUI)
        _GDIPlus_PathAddLine($hPath, $aMC[0], $aMC[1], $aMC[0] + 0.1, $aMC[1] + 0.1)
        _GDIPlus_GraphicsDrawPath($hCanvas, $hPath, $hPen)
        $aMC = GUIGetCursorInfo($hGUI)
    WEnd
    _GDIPlus_PathReset($hPath)
EndFunc

Func _Exit()
    GUISetCursor($om, 1, $hGUI)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
    _WinAPI_DeleteObject($HBITMAP)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_ImageDispose($hBmp)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc

 

Edited by UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Here a little modified version from the code above:

#Include <ScreenCapture.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

_GDIPlus_Startup()

Global Const $HBITMAP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight, 0)

Global Const $hGUI = GUICreate("Draw on bitmap by UEZ", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
GUISetState(@SW_SHOW, $hGUI)

Global Const $hCanvas = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsSetSmoothingMode($hCanvas, 4)
_GDIPlus_GraphicsSetPixelOffsetMode($hCanvas, 4)

Global Const $hBmp = _GDIPlus_BitmapCreateFromHBITMAP($HBITMAP)
_GDIPlus_GraphicsDrawImage($hCanvas, $hBmp, 0, 0)

Global Const $hPen = _GDIPlus_PenCreate(0xFFFF0000, 16)
_GDIPlus_PenSetLineJoin($hPen, 2)
Global Const $hPath = _GDIPlus_PathCreate()

GUISetOnEvent(-3, "_Exit")
OnAutoItExitRegister("_Exit")
GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "Draw", $hGUI)

Global Const $om = MouseGetCursor()

While Sleep(100000)
WEnd

Func Draw()
    Local $aMC = GUIGetCursorInfo($hGUI)
    While Sleep(10) * $aMC[2]
        GUISetCursor(0, 1, $hGUI)
        _GDIPlus_PathAddLine($hPath, $aMC[0], $aMC[1], $aMC[0] + 0.1, $aMC[1] + 0.1)
        _GDIPlus_GraphicsDrawPath($hCanvas, $hPath, $hPen)
        $aMC = GUIGetCursorInfo($hGUI)
    WEnd
    _GDIPlus_PathReset($hPath)
EndFunc

Func _Exit()
    GUISetCursor($om, 1, $hGUI)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "")
    _WinAPI_DeleteObject($HBITMAP)
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_PathDispose($hPath)
    _GDIPlus_GraphicsDispose($hCanvas)
    _GDIPlus_ImageDispose($hBmp)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc

 

Great! As always you'r amazing! Thanks a lot :P

Share this post


Link to post
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