devrandom Posted March 21, 2011 Posted March 21, 2011 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 :|
UEZ Posted March 21, 2011 Posted March 21, 2011 You have to redraw the graphic when it gets erased! Here a simple example: expandcollapse popup#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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
devrandom Posted March 21, 2011 Author Posted March 21, 2011 You have to redraw the graphic when it gets erased! Here a simple example: expandcollapse popup#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
UEZ Posted March 21, 2011 Posted March 21, 2011 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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
devrandom Posted March 21, 2011 Author Posted March 21, 2011 Mhhh I think I resolved The script is not too slow at all
wraithdu Posted March 21, 2011 Posted March 21, 2011 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.
devrandom Posted March 21, 2011 Author Posted March 21, 2011 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
UEZ Posted March 21, 2011 Posted March 21, 2011 E.g. this way: expandcollapse popup#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!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
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