Sign in to follow this  
Followers 0
Yoriz

GDIPlusDispose UDF (No longer req's autoitobject)

12 posts in this topic

#1 ·  Posted (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

#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 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.

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Yeah - I like :mellow:

It works and it´s easy to update older GDI+ scripts!

(...you have AutoitObject.au3 still included...)

Glad you like it :P , 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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

#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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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_StringFormatDispose

Conflicts in helpfile/Unsure what to do with

_GDIPlus_BitmapCloneArea

Remarks__________GDIPlus_BitmapDispose

Example__________GDIPlus_ImageDispose

Using____________WinAPI_DeleteObject (so i have an error of my own but which of the above should i use)

_GDIPlus_BitmapCreateHBITMAPFromBitmap

Remarks__________WinAPI_DeleteObject

Example__________Does not dispose at all

Using____________WinAPI_DeleteObject (same as remarks)

_GDIPlus_ImageGetGraphicsContext

Remarks__________Does not say to dispose

Example__________GDIPlus_GraphicsDispose

Using____________Im not disposing

_GDIPlus_PenGetCustomEndCap

Remarks_________Does not say to dispose

Example_________Does not show disposing

Using___________I have a dispose but nothing is ever added to the cap list

Says it returns Handle to a CustomLineCap but does not say use _GDIPlus_CustomLineCapDispose

Manually watches only

  • Create_______________________________________type_____________dispose
  • _GDIPlus_GraphicsGetDC_______________________DC_______________GDIPlus_GraphicsReleaseDC
_GDIPlus_GraphicsGetDC

Remarks_________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 used

Using___________Only monitors this for manual create and dispose

Thanks 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.

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  
Followers 0