Andreik Posted July 8, 2008 Share Posted July 8, 2008 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. Link to comment Share on other sites More sharing options...
monoceres Posted July 8, 2008 Share Posted July 8, 2008 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! Link to comment Share on other sites More sharing options...
Andreik Posted July 8, 2008 Author Share Posted July 8, 2008 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. Link to comment Share on other sites More sharing options...
monoceres Posted July 8, 2008 Share Posted July 8, 2008 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! Link to comment Share on other sites More sharing options...
Andreik Posted July 8, 2008 Author Share Posted July 8, 2008 How can I do, if I don't release mouse left click, to continue drawing, like in paint. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
monoceres Posted July 8, 2008 Share Posted July 8, 2008 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! Link to comment Share on other sites More sharing options...
Andreik Posted July 8, 2008 Author Share Posted July 8, 2008 Work fine. Thanks. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
monoceres Posted July 8, 2008 Share Posted July 8, 2008 (edited) 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 July 8, 2008 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Andreik Posted July 8, 2008 Author Share Posted July 8, 2008 Nice script. It`s perfect. Thank you very much. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Zedna Posted July 8, 2008 Share Posted July 8, 2008 You can use simpler SetPixel API. There are examples on the forum for it. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Andreik Posted July 8, 2008 Author Share Posted July 8, 2008 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. 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