Jump to content
Sign in to follow this  

Moving Graphic's content

Recommended Posts


Is there a way to move GDI+ graphic's content? In theory it should sound like this:

Create Graphic and it's back buffer, capture the buffer's picture and then draw it somewhere on the original graphic, like this:

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>


Func _Main()
    Local $hGUI = GUICreate("GDI+", 400, 300)
    Local $hWnd = WinGetHandle("GDI+")

    _GDIPlus_Startup ()
    Local $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
    Local $bitmap = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphic)
    Local $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    Local $hBrush = _GDIPlus_BrushCreateSolid (0xFF000000)
    Local $tLayout = _GDIPlus_RectFCreate (1/400, 1/300, 0, 0)
    Local $font_size = 18
    Local $hFormat = _GDIPlus_StringFormatCreate ()
    Local $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
    Local $hFont = _GDIPlus_FontCreate ($hFamily, $font_size, 2)
    _GDIPlus_GraphicsDrawStringEx ($backbuffer, "some GDI graph. content", $hFont, $tLayout, $hFormat, $hBrush)

    Local $GC = _GDIPlus_ImageGetGraphicsContext($bitmap)
    Local $newBmp = _GDIPlus_BitmapCreateFromGraphics(400, 300, $GC)
    Local $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp)
    _GDIPlus_GraphicsDrawImageRect($newGC, $bitmap, 0, 0, 400, 300)
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $bitmap, 0, 0, 400, 300)

    MsgBox(0, "", "now we move the GDI")
    for $i = 0 to 150
        _move_the_gdi($hGraphic, $bitmap, $i/2, $i)
    _move_the_gdi($hGraphic, $bitmap, 90, 180)

    Until GUIGetMsg() = $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_Shutdown ()

EndFunc   ;==>_Main

func _move_the_gdi($grhp, $btmp, $_x_coord, $_y_coord)
    _GDIPlus_GraphicsDrawImageRect($grhp, $btmp, $_x_coord, $_y_coord, 400, 300)

is there a simpler way (without buffers)? Or maybe there's a GDI plus command for moving the graphic content which I've missed :P

Share this post

Link to post
Share on other sites

Don't look at the graphics object as a container for pixel data, instead look at them as doors that allows you to adjust pixel data in real places. For example a graphics object created for an hwnd only adjust the pixels on the window, they are never saved anywhere else. Therefore you must save your data inside bitmaps if you want to save old contents and redraw it in a new place.

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

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