polps 1 Posted December 6, 2020 (edited) Hi all, I'm starting to learn about GDI+ following the help examples. I started drawing a simple line and it's working (see my code). I'm facing now this problem: when I move the window the line still exists, but when I resize, minimize or maximize the window, the line disappear... Do I need to redraw the line anytime? How? Thanks in advance. expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ;create a Graphics object from a window handle $hGUI = GUICreate("_GDIPlus_CustomLineCapCreate Example", 400,300,200,200, BitOR($WS_SIZEBOX ,$WS_MAXIMIZEBOX, $WS_MINIMIZEBOX ) ) GUISetBkColor(0x303030 , $hGUI) GUISetState(@SW_SHOW) _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) $hPen = _GDIPlus_PenCreate(0xFFFF0000, 5) ; $hBrush = _GDIPlus_BrushCreateSolid(0xFFE0A0FF) ;color format AARRGGBB (hex) ;_GDIPlus_GraphicsDrawEllipse($hGraphic, 130, 100, 140, 70, $hPen ) ;_GDIPlus_GraphicsFillEllipse($hGraphic, 130, 100, 140, 70, $hBrush ) _GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) GUISetOnEvent($GUI_EVENT_CLOSE, "End") Do Until Not Sleep(100) Func End() _GDIPlus_PenDispose ( $hPen ) ;_GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunc Edited December 6, 2020 by polps Share this post Link to post Share on other sites
Nine 994 Posted December 6, 2020 You should always use a back buffer (see forum examples). Just redraw the back buffer for no flickering. Not much of a signature but working on it... Spoiler Block all input without UAC Save/Retrieve Images to/from Text Tool to search content in au3 files Date Range Picker Sudoku Game 2020 Overlapped Named Pipe IPC x64 Bitwise Operations Multi-keyboards HotKeySet Fast and simple WCD IPC Multiple Folder Selector GIF Animation (cached) Share this post Link to post Share on other sites
Sidley 18 Posted December 7, 2020 At the moment, the line only draws once, when you resize the GUI the line will have to be redrawn. I'm sure there's a way to do this on a GUI resize event, but for the moment it's probably easier to just constantly redraw the line in the do..while loop starting on line 28. And as @Nine said using a back buffer should always be used with GDI plus graphics, especially when you start adding more and more complex images. It basically assembles all the graphics in the background before presenting the completed image to the screen. expandcollapse popup#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ;create a Graphics object from a window handle $hGUI = GUICreate("_GDIPlus_CustomLineCapCreate Example", 400,300,200,200, BitOR($WS_SIZEBOX ,$WS_MAXIMIZEBOX, $WS_MINIMIZEBOX ) ) GUISetBkColor(0x303030 , $hGUI) GUISetState(@SW_SHOW) _GDIPlus_Startup() $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Local $bitmap = _GDIPlus_BitmapCreateFromGraphics(400, 300, $hGraphic) ;Create bitmap object Local $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap) ;Create backbuffer $hPen = _GDIPlus_PenCreate(0xFFFF0000, 5) ; $hBrush = _GDIPlus_BrushCreateSolid(0xFFE0A0FF) ;color format AARRGGBB (hex) ;_GDIPlus_GraphicsDrawEllipse($hGraphic, 130, 100, 140, 70, $hPen ) ;_GDIPlus_GraphicsFillEllipse($hGraphic, 130, 100, 140, 70, $hBrush ) ;_GDIPlus_GraphicsDrawLine($hGraphic, 10, 150, 390, 150, $hPen) GUISetOnEvent($GUI_EVENT_CLOSE, "End") Do _GDIPlus_GraphicsClear($backbuffer, 0xFF000000 + 0x303030) ;Fill the GUI with background colour (Overwrite the old line) _GDIPlus_GraphicsDrawLine($backbuffer, 10, 150, 390, 150, $hPen) ;Redraw the line to the back buffer _GDIPlus_GraphicsDrawImageRect($hGraphic, $bitmap, 0, 0, 400, 300);Draw the backbuffer to the screen Until Not Sleep(100) Func End() _GDIPlus_GraphicsDispose($backbuffer) ;Dispose of back buffer _GDIPlus_PenDispose ( $hPen ) ;_GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunc Share this post Link to post Share on other sites
polps 1 Posted December 7, 2020 Thanks Nine and Sidley! Share this post Link to post Share on other sites