Sign in to follow this  
Followers 0
devrandom

GDI+ problem :|

9 posts in this topic

Why when I minimize a window, the GDI+ graphics are cleaned?

_GDIPlus_Startup()

$hGui = GUICreate("test", 600, 400)

GUISetState(@SW_SHOW, $hGui)

$graphics = _GDIPlus_GraphicsCreateFromHWND($hGui)

_GDIPlus_GraphicsFillRect($graphics, 0, 0, 300, 400, _GDIPlus_BrushCreateSolid(0xFFFFFFFF))

If I minimize and the maximize the window, the white rect disappears :|

Share this post


Link to post
Share on other sites



You have to redraw the graphic when it gets erased!

Here a simple example:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt('MustDeclareVars', 1)

Local $iW = 320
Local $iH = 320
Local $hWnd = GUICreate("GDI+ Redraw Window", $iW, $iH)
GUISetState()
GUISetOnEvent(-3, "_Close")

_GDIPlus_Startup()
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Local $pen_size = 128
Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, $pen_size)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

Draw()
GUIRegisterMsg($WM_ERASEBKGND, "Draw")

While Sleep(30000)
WEnd

Func Draw()
    _GDIPlus_GraphicsClear($hBackbuffer)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $pen_size / 2, $pen_size / 2, $iW - $pen_size, $iH - $pen_size, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
    Return 1
EndFunc

Func _Close()
    GUIRegisterMsg($WM_ERASEBKGND, "")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
EndFunc

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

You have to redraw the graphic when it gets erased!

Here a simple example:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt('MustDeclareVars', 1)

Local $iW = 320
Local $iH = 320
Local $hWnd = GUICreate("GDI+ Redraw Window", $iW, $iH)
GUISetState()
GUISetOnEvent(-3, "_Close")

_GDIPlus_Startup()
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Local $pen_size = 128
Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, $pen_size)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

Draw()
GUIRegisterMsg($WM_ERASEBKGND, "Draw")

While Sleep(30000)
WEnd

Func Draw()
    _GDIPlus_GraphicsClear($hBackbuffer)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $pen_size / 2, $pen_size / 2, $iW - $pen_size, $iH - $pen_size, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
    Return 1
EndFunc

Func _Close()
    GUIRegisterMsg($WM_ERASEBKGND, "")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
EndFunc

Br,

UEZ

Thank you :)

The problem is that I have a lot of polygons to redraw :S

Share this post


Link to post
Share on other sites

Show your script and maybe I can help.

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

Mhhh I think I resolved :)

The script is not too slow at all :)

Share this post


Link to post
Share on other sites

Might make better sense to draw the polygons once to a buffer (and again when updated), then in the _Draw() function just draw the buffer to the graphic.

Share this post


Link to post
Share on other sites

How can I do this? :S

Maybe I can create a empty bitmap, convert to a "graphics" object and draw into this... But after drawing in the "backbuffer" how can I draw it into the GUI's graphics? :)

P.S. Sorry for my bad english :)

Share this post


Link to post
Share on other sites

E.g. this way:

#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
Opt('MustDeclareVars', 1)

Local $iW = 320
Local $iH = 320
Local $hWnd = GUICreate("GDI+ Redraw Window", $iW, $iH)
GUISetState()
GUISetOnEvent(-3, "_Close")

_GDIPlus_Startup()
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hGraphics)
Local $hBackbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Local $pen_size = 128
Local $hPen = _GDIPlus_PenCreate(0xFF00FF00, $pen_size)
_GDIPlus_GraphicsSetSmoothingMode($hBackbuffer, 2)

Draw()
GUIRegisterMsg($WM_ERASEBKGND, "WM_ERASEBKGND")

While Sleep(30000)
WEnd

Func Draw()
    _GDIPlus_GraphicsClear($hBackbuffer)
    _GDIPlus_GraphicsDrawEllipse($hBackbuffer, $pen_size / 2, $pen_size / 2, $iW - $pen_size, $iH - $pen_size, $hPen)
    _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
EndFunc

Func WM_ERASEBKGND()
        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hBitmap, 0, 0, $iW, $iH)
        Return 1
EndFunc

Func _Close()
    GUIRegisterMsg($WM_ERASEBKGND, "")
    _GDIPlus_PenDispose($hPen)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hBackbuffer)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hWnd)
    Exit
EndFunc

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

Thank you :)

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