monoscout999 Posted September 26, 2011 Share Posted September 26, 2011 (edited) Hello. i like to do a litle paint just for fun, i want that the user draw an ellipse in the GUI, i cannot erase the pre drawing. I want that someone with experience in this kind of program give me some hint. this is my try. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <Winapi.au3> #include <GDIPlus.au3> Global Const $SC_MOVE = 0xF010 Global Const $STM_SETIMAGE = 0x172 Global Const $STM_GETIMAGE = 0x173 Global $img = @ScriptDir & "\bot2.bmp" InetGet("http://www.mediafire.com/imgbnc.php/c83b527a400083eedd4f6958da2d9f6f1db83d5f6513f59045fae80a37df1e276g.jpg", $img) $hGUI = GUICreate("Graficos Simples GDI+") $Pic = GUICtrlCreatePic($img, 0, 0, 400, 400) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN _CreatingBox($Pic) EndSwitch WEnd Func _CreatingBox($iPic) Local $hPic = GUICtrlGetHandle($iPic) Local $aCursor = GUIGetCursorInfo() Local $x = $aCursor[0] Local $y = $aCursor[1] _GDIPlus_Startup() Local $hBMP = GUICtrlSendMsg($iPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Local $hGrap = _GDIPlus_ImageGetGraphicsContext($hImage) Local $hDC = _WinAPI_GetDC($hGUI) Local $hAuxGraph = _GDIPlus_GraphicsCreateFromHDC($hDC) Do $aCursor = GUIGetCursorInfo() _GDIPlus_GraphicsDrawEllipse($hAuxGraph, $x, $y, $aCursor[0] - $x, $aCursor[1] - $y) _WinAPI_PostMessage($hGUI, $WM_ERASEBKGND, $hDC, 0) ;~ _WinAPI_PostMessage($hGUI, $WM_PAINT, 0, 0) ;~ _winapi_updatewindow($hGUI) Until Not $aCursor[2] _GDIPlus_GraphicsDispose($hAuxGraph) _WinAPI_ReleaseDC($hGUI, $hDC) _GDIPlus_GraphicsDrawEllipse($hGrap, $x, $y, $aCursor[0] - $x, $aCursor[1] - $y) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)) _WinAPI_DeleteObject($hBitmap) _GDIPlus_GraphicsDispose($hGrap) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc ;==>_CreatingBox Edited September 27, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
Ramzes Posted September 26, 2011 Share Posted September 26, 2011 My ellipse drawing code: #include <GDIPlus.au3> #include <Array.au3> _GDIPlus_Startup() Global Const $MainWindow = GUICreate("Ellipse Test", 800, 600) GUISetState() $hImage = _GDIPlus_BitmapCreateFromFile("bo3t2.bmp") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($MainWindow) $Width = _GDIPlus_ImageGetWidth($hImage) $Height = _GDIPlus_ImageGetHeight($hImage) $Return = _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, 800, 600) ; Draw ellipse _GDIPlus_GraphicsDrawEllipse($hGraphic, 110, 110, 300, 100) _GDIPlus_GraphicsDrawString($hGraphic, "Ramzes =)", 135, 125, "Arial", 32) While 1 Sleep(10) WEnd You can edit it. Sorry for my bad English but nobody is perfect. [font=arial, helvetica, sans-serif]Ramzes[/font] Link to comment Share on other sites More sharing options...
monoscout999 Posted September 26, 2011 Author Share Posted September 26, 2011 (edited) ok @Ramzes but i am looking a way to draw when you click and drag on the GUI. Edited September 26, 2011 by monoscout999 Link to comment Share on other sites More sharing options...
bogQ Posted September 26, 2011 Share Posted September 26, 2011 (edited) expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <Winapi.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> Global Const $SC_MOVE = 0xF010, $STM_SETIMAGE = 0x172, $STM_GETIMAGE = 0x173 Global $hBMP = @ScriptDir & "\bot2.bmp", $temp InetGet("http://www.mediafire.com/imgbnc.php/c83b527a400083eedd4f6958da2d9f6f1db83d5f6513f59045fae80a37df1e276g.jpg", $hBMP) $hGUI = GUICreate("GDI+", 400, 300) GUISetState() _GDIPlus_Startup() $hBitmap = _GDIPlus_BitmapCreateFromFile($hBMP) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, 0, 0, 50, 50, 0, 0, 400, 300) While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE _GDIPlus_Shutdown() Exit Case $GUI_EVENT_PRIMARYDOWN _CreatingBox() EndSwitch WEnd Func _CreatingBox() Local $aCursor = GUIGetCursorInfo($hGUI) Local $x = $aCursor[0], $y = $aCursor[1] Local $1 = $aCursor[0], $2 = $aCursor[1] Do $aCursor = GUIGetCursorInfo($hGUI) If $1 <> $aCursor[0] Or $2 <> $aCursor[1] Then $1 = $aCursor[0] $2 = $aCursor[1] _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hBitmap, 0, 0, 50, 50, 0, 0, 400, 300) _GDIPlus_GraphicsDrawEllipse($hGraphic, $x, $y, $aCursor[0] - $x, $aCursor[1] - $y) EndIf Until Not $aCursor[2] EndFunc ;==>_CreatingBox something similar to this? (i did not clean it up from memory before exit, you can do that yourself if this is what you need) Edit: this code taging is killing me, dont work on tabs direcly from scite and make them to spaces and if i copy and even with autoit code tags it put the dumb link in script for picture if you dont use autoit stule so you cant manyaly write the tags Edited September 26, 2011 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.  Link to comment Share on other sites More sharing options...
monoscout999 Posted September 27, 2011 Author Share Posted September 27, 2011 (edited) thanks BogQ this is solved and added a backbuffer to smoth the process. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Constants.au3> #include <Winapi.au3> #include <GDIPlus.au3> Global Const $SC_MOVE = 0xF010 Global Const $STM_SETIMAGE = 0x172 Global Const $STM_GETIMAGE = 0x173 Global $img = @ScriptDir & "\bot2.bmp" InetGet("http://www.mediafire.com/imgbnc.php/c83b527a400083eedd4f6958da2d9f6f1db83d5f6513f59045fae80a37df1e276g.jpg", $img) $hGUI = GUICreate("Graficos Simples GDI+") $Pic = GUICtrlCreatePic($img, 0, 0, 400, 400) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState() While True $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN _CreatingBox($Pic) EndSwitch WEnd Func _CreatingBox($iPic) Local $hPic = GUICtrlGetHandle($iPic) Local $aCursor = GUIGetCursorInfo() Local $x = $aCursor[0] Local $y = $aCursor[1] Local $oldX = $x Local $oldY = $y _GDIPlus_Startup() Local $hBMP = GUICtrlSendMsg($iPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0) Local $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) Local $auxBMP = _GDIPlus_BitmapCloneArea($hImage, 0, 0, 400, 400) Local $hGrap = _GDIPlus_ImageGetGraphicsContext($hImage) Local $hDC = _WinAPI_GetDC($hGUI) Local $hAuxGraph = _GDIPlus_GraphicsCreateFromHDC($hDC) local $hBrush = _GDIPlus_BrushCreateSolid(0x447722FF) Do $aCursor = GUIGetCursorInfo($hGUI) If $oldX <> $aCursor[0] Or $oldY <> $aCursor[1] Then $oldX = $aCursor[0] $oldY = $aCursor[1] _GDIPlus_GraphicsDrawImageRect($hGrap, $auxBMP, 0, 0, 400, 400) _GDIPlus_GraphicsfillEllipse($hGrap, $x, $y, $aCursor[0] - $x, $aCursor[1] - $y,$hBrush) _GDIPlus_GraphicsDrawImageRect($hAuxGraph, $hImage, 0, 0, 400, 400) EndIf Until Not $aCursor[2] _gdiplus_brushdispose($hBrush) _GDIPlus_GraphicsDispose($hAuxGraph) _WinAPI_ReleaseDC($hGUI, $hDC) Local $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage) _WinAPI_DeleteObject(GUICtrlSendMsg($iPic, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap)) _WinAPI_DeleteObject($hBitmap) _GDIPlus_GraphicsDispose($hGrap) _GDIPlus_ImageDispose($auxBMP) _GDIPlus_ImageDispose($hImage) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc ;==>_CreatingBox Edited September 27, 2011 by monoscout999 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