Jump to content

Recommended Posts

Posted

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 :|

Posted

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

Posted

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

Posted

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.

Posted

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 :)

Posted

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

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...