Yoriz Posted June 11, 2010 Share Posted June 11, 2010 (edited) Huh wtf why change the gdiplus udf ? I made a version that you dont have to keep track of the objects that need to be disposed of before shutdown of the dll. But How do i use it ? All the functions are called in the same way the only one that is slightly changed is _GDIPlus_Startup() can take a parameter. Damn what the hell have you done to the start up ? See the following ; Syntax.........: _GDIPlus_Startup($fConsoleOut = False) ; Parameters ....: $fConsoleOut - Set true or False for feed back in console of created and destoryed graphic objects SO what does it do again ?? As you create GDI objects they are stored in variables, you can dispose of them in the normal way and they will be removed from the list, any that you dont dispose of yourself will be disposed of automatically when you call '_GDIPlus_Shutdown' Here is an example script expandcollapse popup#include <GDIPlusDispose.au3> #include <GuiConstants.au3> #include <WindowsConstants.au3> Global $hGraphicGUI, $hBMPBuff _GdiGui() Func _GdiGui() Local $hGui, $GuiSizeX = 300, $GuiSizeY = 300 $hGui = GUICreate("GDIPlus Example", $GuiSizeX, $GuiSizeY) GUISetState() _GDIPlus_Startup(True) $hPen = _GDIPlus_PenCreate(0xFFFF0000, 3) ; Create Double Buffer, so the doesn't need to be repainted on PAINT-Event $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui) ;Draw to this graphics, $hGraphicGUI, to display on GUI $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI); $hBMPBuff is a bitmap in memory $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff); Draw to this graphics, $hGraphic, being the graphics of $hBMPBuff ;End Double Buffer add-in 1 of 3 $hStoreAsBitmapInMemory = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI) $hMyGraphicGraphic = _GDIPlus_ImageGetGraphicsContext($hStoreAsBitmapInMemory) _GDIPlus_GraphicsDrawRect($hMyGraphicGraphic, 20, 20, 260, 260, $hPen) _GDIPlus_GraphicsDrawImage($hGraphic, $hStoreAsBitmapInMemory, 0, 0) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0); Draw bitmap, $hBMPBuff, to the GUI's graphics, $hGraphicGUI. _GDIPlus_GraphicsDrawLine($hGraphic, 20, 150, 280, 150, $hPen) GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3) GUIRegisterMsg(0x85, "MY_PAINT") ; $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize. _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0); Draw bitmap, $hBMPBuff, to the GUI's graphics, $hGraphicGUI. $hTestArrowCapCreate = _GDIPlus_ArrowCapCreate(10, 10) $hTestBrushCreate = _GDIPlus_BrushCreateSolid() $hTestFamilyCreate = _GDIPlus_FontFamilyCreate("Arial") $hTestFontCreate = _GDIPlus_FontCreate($hTestFamilyCreate, 12, 2) $hTestMatrixCreate = _GDIPlus_MatrixCreate() $hTestFormatCreate = _GDIPlus_StringFormatCreate() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() EndSwitch WEnd EndFunc ;==>_GdiGui ;Func to auto-redraw on Windows internal PAINT messages. Func MY_PAINT($hWnd, $msg, $wParam, $lParam) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) ;_WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN Return $GUI_RUNDEFMSG EndFunc ;==>MY_PAINT Func _Exit() _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit The output to console from this is as follows 0x017D3758 - Added as type: Pen 0x017D3918 - Added as type: Graphics 0x017D3BF0 - Added as type: Bitmap 0x017D43B8 - Added as type: Bitmap 0x022706E0 - Added as type: ArrowCap 36113096 - Added as type: Brush 0x017D4E80 - Added as type: FontFamily 0x017D7F30 - Added as type: Font 0x0227E438 - Added as type: Matrix 0x017DFE50 - Added as type: String ****** Disposing of GdiPlus Objects Before shuting down dll ****** 0x022706E0 - Successfully Auto disposed of type: ArrowCap 0x017D3BF0 - Successfully Auto disposed of type: Bitmap 0x017D43B8 - Successfully Auto disposed of type: Bitmap 36113096 - Successfully Auto disposed of type: Brush 0x017D7F30 - Successfully Auto disposed of type: Font 0x017D4E80 - Successfully Auto disposed of type: FontFamily 0x017D3918 - Successfully Auto disposed of type: Graphics 0x0227E438 - Successfully Auto disposed of type: Matrix 0x017D3758 - Successfully Auto disposed of type: Pen 0x017DFE50 - Successfully Auto disposed of type: String Edit: This no longer require's the use of AutoitObject, its totally self contained and is now named 'GDIPlusDispose' Cheers Yoriz.GDIPlusDispose.au3 Edited June 11, 2010 by Yoriz GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
UEZ Posted June 11, 2010 Share Posted June 11, 2010 Nice idea! Maybe we can rid off the disposing... I will check it! BR, 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
jaberwacky Posted June 11, 2010 Share Posted June 11, 2010 Sweet, this will help my future GDI+ experiments! Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Yoriz Posted June 11, 2010 Author Share Posted June 11, 2010 I have modified the first post with a new version that does not require's the use of 'AutoitObjectUDF', its totally self dependant using just normal variables to store the object list. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
eukalyptus Posted June 11, 2010 Share Posted June 11, 2010 Yeah - I like It works and it´s easy to update older GDI+ scripts! (...you have AutoitObject.au3 still included...) DirectSound UDF Direct2D UDF Link to comment Share on other sites More sharing options...
Yoriz Posted June 11, 2010 Author Share Posted June 11, 2010 Yeah - I like It works and it´s easy to update older GDI+ scripts! (...you have AutoitObject.au3 still included...)Glad you like it , Thanks for pointing that out, ive removed the #include "AutoitObject.au3" from the top of the script and uploaded the new version. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
Authenticity Posted June 11, 2010 Share Posted June 11, 2010 Great idea, GDI+ code with OOP principles never was closer for AutoIt. I just want to know. I don't know how AutoitObjectUDF is implemented... Does objects that go out of scope still remain in memory? Should we dispose them explicitly? Link to comment Share on other sites More sharing options...
trancexx Posted June 11, 2010 Share Posted June 11, 2010 Great idea, GDI+ code with OOP principles never was closer for AutoIt. I just want to know. I don't know how AutoitObjectUDF is implemented... Does objects that go out of scope still remain in memory? Should we dispose them explicitly?No. Release is called and memory is freed completely.(Except for the case of cyclic references, but that's wider issue)...Yoriz switched to AutoitObject-free version. ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Authenticity Posted June 11, 2010 Share Posted June 11, 2010 I mean, if I call a function extensively (true, I can use Static) and the function return. The objects will be in the list of dispose objects, but still remain in memory. Usually, I don't need a few dozens or so of them. Only when they're explicitly created and disposed by me. expandcollapse popup#include "GDIPlusDispose.au3" #include <GuiConstants.au3> #include <WindowsConstants.au3> Global $hGraphicGUI, $hBMPBuff _GdiGui() Func _GdiGui() Local $hGui, $GuiSizeX = 300, $GuiSizeY = 300 $hGui = GUICreate("GDIPlus Example", $GuiSizeX, $GuiSizeY) GUISetState() _GDIPlus_Startup(True) $hPen = _GDIPlus_PenCreate(0xFFFF0000, 3) ; Create Double Buffer, so the doesn't need to be repainted on PAINT-Event $hGraphicGUI = _GDIPlus_GraphicsCreateFromHWND($hGui) ;Draw to this graphics, $hGraphicGUI, to display on GUI $hBMPBuff = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI); $hBMPBuff is a bitmap in memory $hGraphic = _GDIPlus_ImageGetGraphicsContext($hBMPBuff); Draw to this graphics, $hGraphic, being the graphics of $hBMPBuff ;End Double Buffer add-in 1 of 3 $hStoreAsBitmapInMemory = _GDIPlus_BitmapCreateFromGraphics($GuiSizeX, $GuiSizeY, $hGraphicGUI) $hMyGraphicGraphic = _GDIPlus_ImageGetGraphicsContext($hStoreAsBitmapInMemory) _GDIPlus_GraphicsDrawRect($hMyGraphicGraphic, 20, 20, 260, 260, $hPen) _GDIPlus_GraphicsDrawImage($hGraphic, $hStoreAsBitmapInMemory, 0, 0) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0); Draw bitmap, $hBMPBuff, to the GUI's graphics, $hGraphicGUI. _GDIPlus_GraphicsDrawLine($hGraphic, 20, 150, 280, 150, $hPen) GUIRegisterMsg(0xF, "MY_PAINT"); Register PAINT-Event 0x000F = $WM_PAINT (WindowsConstants.au3) GUIRegisterMsg(0x85, "MY_PAINT") ; $WM_NCPAINT = 0x0085 (WindowsConstants.au3)Restore after Minimize. _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0); Draw bitmap, $hBMPBuff, to the GUI's graphics, $hGraphicGUI. $hTestArrowCapCreate = _GDIPlus_ArrowCapCreate(10, 10) $hTestBrushCreate = _GDIPlus_BrushCreateSolid() $hTestFamilyCreate = _GDIPlus_FontFamilyCreate("Arial") $hTestFontCreate = _GDIPlus_FontCreate($hTestFamilyCreate, 12, 2) $hTestMatrixCreate = _GDIPlus_MatrixCreate() $hTestFormatCreate = _GDIPlus_StringFormatCreate() _Test($hGraphicGUI) _Test($hGraphicGUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() EndSwitch WEnd EndFunc ;==>_GdiGui ;Func to auto-redraw on Windows internal PAINT messages. Func MY_PAINT($hWnd, $msg, $wParam, $lParam) _GDIPlus_GraphicsDrawImage($hGraphicGUI, $hBMPBuff, 0, 0) ;_WinAPI_RedrawWindow($hGui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME)) ; , $RDW_ALLCHILDREN Return $GUI_RUNDEFMSG EndFunc ;==>MY_PAINT Func _Exit() _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit Func _Test($hGraphics) Local $hBmp = _GDIPlus_BitmapCreateFromGraphics(200, 200, $hGraphics) ; Do something with both ; No value is returned EndFunc Link to comment Share on other sites More sharing options...
eukalyptus Posted June 12, 2010 Share Posted June 12, 2010 Hi missing: ? _GDIPlus_ImageGetGraphicsContext: __GDIPlus_ObjectDispose_ListAdd($aResult[2], "Graphics") I often use functions to create a bitmap. All created stuff needs to be disposed, except $hBitmap - maybe you could create functions to do so: Func _CreateBitmap($hGraphics, $iWidth, $iHeight) _GDIPlus_DisposeBegin() Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iWidth, $iHeight, $hGraphics) Local $hContext = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsClear($hContext,0xFF000000) Local $hBrush = _GDIPlus_BrushCreateSolid(0xE0000000) Local $hFormat = _GDIPlus_StringFormatCreate() Local $hFamily = _GDIPlus_FontFamilyCreate("Arial") Local $hFont = _GDIPlus_FontCreate($hFamily, 10, 0) ;... _GDIPlus_DisposeNow($hBitmap) ; dispose all but $hBitmap Return $hBitmap EndFunc E DirectSound UDF Direct2D UDF Link to comment Share on other sites More sharing options...
James Posted June 12, 2010 Share Posted June 12, 2010 "Shutting" not "shuting" Other than that, useful! I wonder why this wasn't done before O_o James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Yoriz Posted June 12, 2010 Author Share Posted June 12, 2010 I'm a little confused about a few of the graphic objects that may/maynot need diposing or by which dispose function.These are the ones i have at the moment.Create_______________________________________type_____________dispose_GDIPlus_ArrowCapCreate______________________ArrowCap_________GDIPlus_ArrowCapDispose_GDIPlus_BitmapCloneArea_____________________BitmapObj________WinAPI_DeleteObject_GDIPlus_BitmapCreateFromFile________________Bitmap___________GDIPlus_BitmapDispose_GDIPlus_BitmapCreateFromGraphics____________Bitmap___________GDIPlus_BitmapDispose_GDIPlus_BitmapCreateFromHBITMAP_____________Bitmap___________GDIPlus_BitmapDispose_GDIPlus_BitmapCreateHBITMAPFromBitmap_______BitmapObj________WinAPI_DeleteObject_GDIPlus_BrushClone__________________________Brush____________GDIPlus_BrushDispose_GDIPlus_BrushCreateSolid____________________Brush____________GDIPlus_BrushDispose_____________________________________________Cap______________GDIPlus_CustomLineCapDispose_GDIPlus_FontCreate__________________________Font_____________GDIPlus_FontDispose_GDIPlus_FontFamilyCreate____________________FontFamily_______GDIPlus_FontFamilyDispose_GDIPlus_GraphicsCreateFromHDC_______________Graphics_________GDIPlus_GraphicsDispose_GDIPlus_GraphicsCreateFromHWND______________Graphics_________GDIPlus_GraphicsDispose_____________________________________________Image____________GDIPlus_ImageDispose_GDIPlus_MatrixCreate________________________Matrix___________GDIPlus_MatrixDispose_GDIPlus_PenCreate___________________________Pen______________GDIPlus_PenDispose_GDIPlus_StringFormatCreate__________________String___________GDIPlus_StringFormatDisposeConflicts in helpfile/Unsure what to do with_GDIPlus_BitmapCloneAreaRemarks__________GDIPlus_BitmapDisposeExample__________GDIPlus_ImageDisposeUsing____________WinAPI_DeleteObject (so i have an error of my own but which of the above should i use)_GDIPlus_BitmapCreateHBITMAPFromBitmap Remarks__________WinAPI_DeleteObjectExample__________Does not dispose at allUsing____________WinAPI_DeleteObject (same as remarks)_GDIPlus_ImageGetGraphicsContextRemarks__________Does not say to disposeExample__________GDIPlus_GraphicsDisposeUsing____________Im not disposing_GDIPlus_PenGetCustomEndCapRemarks_________Does not say to disposeExample_________Does not show disposingUsing___________I have a dispose but nothing is ever added to the cap listSays it returns Handle to a CustomLineCap but does not say use _GDIPlus_CustomLineCapDisposeManually watches onlyCreate_______________________________________type_____________dispose_GDIPlus_GraphicsGetDC_______________________DC_______________GDIPlus_GraphicsReleaseDC_GDIPlus_GraphicsGetDCRemarks_________Each call to the _GDIPlus_GraphicsGetDC should be paired with a call to the _GDIPlus_GraphicsReleaseDC. Do not call any methods of the Graphics object between the calls.Example_________Not seen this usedUsing___________Only monitors this for manual create and disposeThanks for pointing out the typo JamesBrooks, i've changed my version will upload a new version once the above is sorted out. GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. 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