GDI+ Fenster flackert

  • Hallo,

    wieso flackert das? Wie kann ich dieses flackern weg bekommen?

    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

    [/autoit][autoit][/autoit][autoit]

    Global $width = 302
    Global $height = 302

    [/autoit][autoit][/autoit][autoit]

    $hGUI = GUICreate("BlueJ Figuren Demo", $width, $height)
    $hWnd = WinGetHandle($hGUI)
    ;~ GUISetBkColor(0, $hGUI)
    ;~ GUISetBkColor(0xFFFFFF, $hGUI)
    ;~ WinSetTrans($hGUI, "", 255)
    GUISetState(@SW_SHOW)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)

    [/autoit][autoit][/autoit][autoit]

    _GDIPlus_GraphicsClear($hGraphic)
    _GDIPlus_GraphicsFillPie($hGraphic, $width / 2 - 60 / 2, $height / 2 - 60 / 2, 60, 60, 1, 360, $hBrush)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Local $a = 1

    [/autoit][autoit][/autoit][autoit]

    While GUIGetMsg() <> $GUI_EVENT_CLOSE

    [/autoit][autoit][/autoit][autoit]

    _GDIPlus_GraphicsClear($hGraphic)
    _GDIPlus_GraphicsFillPie($hGraphic, $a, 50, 60, 60, 1, 360, $hBrush)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    $a += 1
    Sleep(10)
    WEnd

    [/autoit]
  • Mit dem Doppelbuffer gehts :)

    Spoiler anzeigen
    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GDIPlus.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $width = 302
    Global $height = 302

    [/autoit] [autoit][/autoit] [autoit]

    $hGUI = GUICreate("BlueJ Figuren Demo", $width, $height)
    $hWnd = WinGetHandle($hGUI)
    ;~ GUISetBkColor(0, $hGUI)
    ;~ GUISetBkColor(0xFFFFFF, $hGUI)
    ;~ WinSetTrans($hGUI, "", 255)
    GUISetState(@SW_SHOW)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_Startup()
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
    $Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic) ;create bitmap
    $backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic, 2)
    $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFF00)

    [/autoit] [autoit][/autoit] [autoit]

    _GDIPlus_GraphicsClear($hGraphic)
    _GDIPlus_GraphicsFillPie($hGraphic, $width / 2 - 60 / 2, $height / 2 - 60 / 2, 60, 60, 1, 360, $hBrush)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Local $a = 1

    [/autoit] [autoit][/autoit] [autoit]

    While GUIGetMsg() <> $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsClear($backbuffer)
    _GDIPlus_GraphicsClear($backbuffer)
    _GDIPlus_GraphicsFillPie($backbuffer, $a, 50, 60, 60, 1, 360, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($hgraphic, $bitmap, 0, 0, $width, $height)

    [/autoit] [autoit][/autoit] [autoit]

    $a += 1
    Sleep(10)
    WEnd

    [/autoit]
  • 2 Anmerkungen zu nuts Beispiel:

    1) man sollte die GDI+ Resourcen wieder herunter fahren:

    [autoit]


    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_BitmapDispose($bitmap)
    _GDIPlus_GraphicsDispose($backbuffer)
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ShutDown ()

    [/autoit]


    2) GUIGetMsg() Methode ist träge, d.h. wenn man die Maus bewegt, bewegt sich auch das Objekt schneller. Einfach Opt("GUIOnEventMode", 1) Methode verwenden (z.B. GUISetOnEvent($GUI_EVENT_CLOSE, "Close"))

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯