polps Posted December 6, 2020 Share 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 Link to comment Share on other sites More sharing options...
Nine Posted December 6, 2020 Share Posted December 6, 2020 You should always use a back buffer (see forum examples). Just redraw the back buffer for no flickering. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Sidley Posted December 7, 2020 Share 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 Link to comment Share on other sites More sharing options...
polps Posted December 7, 2020 Author Share Posted December 7, 2020 Thanks Nine and Sidley! Link to comment Share on other sites More sharing options...
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