Jump to content
Sign in to follow this  
Andreik

GDI+ and paint

Recommended Posts

Andreik

I want to create an area 400x400 like in Paint, when I click in this area to put black color (dot) at mouse x position and y position.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
monoceres

Hi!

Here's a basic idea:

#include <GDIPlus.au3>
#include <misc.au3>
Opt("GUIOnEventMode",1)
Opt("MouseCoordMode",2)
$hwnd=GUICreate("Sample",400,400)
GUISetOnEvent(-3,"close")
GUISetState()

_GDIPlus_Startup()
$graphics=_GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics,0xFFFFFFFF)
$brush=_GDIPlus_BrushCreateSolid(0xFF000000)

$dll=DllOpen("user32.dll")

Do
    If _IsPressed("01",$dll) Then
        _GDIPlus_GraphicsFillRect($graphics,MouseGetPos(0),MouseGetPos(1),2,2,$brush)
        Do
            Sleep(25)
        Until Not _IsPressed("01",$dll)
    EndIf
    Sleep(25)
Until False



Func close()
    _GDIPlus_BrushDispose($brush)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc

muttley


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Andreik

Thanks monoceres, it`s perfect. If I want to switch colors (red, yellow, blue,pink,...) I should modify brush color?

$brush=_GDIPlus_BrushCreateSolid(0xFF000000)


When the words fail... music speaks

Share this post


Link to post
Share on other sites
monoceres

Thanks monoceres, it`s perfect. If I want to switch colors (red, yellow, blue,pink,...) I should modify brush color?

$brush=_GDIPlus_BrushCreateSolid(0xFF000000)
Yup muttley

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Andreik

How can I do, if I don't release mouse left click, to continue drawing, like in paint.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
monoceres

How can I do, if I don't release mouse left click, to continue drawing, like in paint.

Add this to the Do...Until loop inside the If statement:

$pos = MouseGetPos()
_GDIPlus_GraphicsFillRect($graphics, $pos[0], $pos[1], 2, 2, $brush)

You should also remove the sleep.


Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Andreik

Work fine. Thanks.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
monoceres

I made a even better version, it now acts just like paint muttley

#include <GDIPlus.au3>
#include <misc.au3>
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode", 2)
$hwnd = GUICreate("Sample", 400, 400)
GUISetOnEvent(-3, "close")
GUISetState()

_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsClear($graphics, 0xFFFFFFFF)
$pen = _GDIPlus_PenCreate(0xFF00FF00)

$dll = DllOpen("user32.dll")

Do
    If _IsPressed("01", $dll) And WinActive("Sample") Then
        $oldpos=MouseGetPos()
        _GDIPlus_GraphicsDrawRect($graphics,$oldpos[0],$oldpos[1],1,1,$pen)
        Do
            $pos = MouseGetPos()
            _GDIPlus_GraphicsDrawLine($graphics,$oldpos[0],$oldpos[1],$pos[0],$pos[1],$pen)
            $oldpos=$pos
        Until Not _IsPressed("01", $dll)
    EndIf
    Sleep(25)
Until False



Func close()
    _GDIPlus_PenDispose($pen)
    _GDIPlus_GraphicsDispose($graphics)
    _GDIPlus_Shutdown()
    Exit
EndFunc  ;==>close
Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites
Andreik

Nice script. It`s perfect. Thank you very much.


When the words fail... music speaks

Share this post


Link to post
Share on other sites
Andreik

You can use simpler SetPixel API.

There are examples on the forum for it.

Just check, SetPixel is another way. Thanks!


When the words fail... music speaks

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.