Jump to content

GDI plus question


polps
 Share

Recommended Posts

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.

#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 by polps
Link to comment
Share on other sites

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.

#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

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
 Share

  • Recently Browsing   0 members

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