GDIPlus auf durchsichtige GUI zeichnen

  • Ich brauche mal eure Hilfe bei einem GDIPlus-Programm:
    Ich möchte, dass die GUI einen transparenten Hintergrund hat, die GDIPlus-Objekte sollen aber voll sichtbar sein. Mit _WinAPI_SetLayeredWindowAttributes() hab' ich's nicht hinbekommen.

    Spoiler anzeigen
    [autoit]

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

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

    HotKeySet("{ESC}", "_Shut")
    Opt("GUIOnEventMode", 1)

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

    $hGui = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP)
    GUISetOnEvent(-3, "_Shut")
    GUISetBkColor(0x000000)
    GUISetState()

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

    _GDIPlus_Startup()
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphics)
    Global $Backbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hPen = _GDIPlus_PenCreate(0xFFFF0000, 2)

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

    _GDIPlus_GraphicsClear($Backbuffer)
    Sleep(300)

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

    While 1
    $pos = MouseGetPos()
    While _IsPressed("01")
    $pos2 = MouseGetPos()
    _GDIPlus_GraphicsClear($Backbuffer)
    _GDIPlus_GraphicsDrawLine($Backbuffer, $pos[0], $pos[1], $pos2[0], $pos[1], $hPen);Oben horizontal
    _GDIPlus_GraphicsDrawLine($Backbuffer, $pos[0], $pos[1], $pos[0], $pos2[1], $hPen);Links vertikal
    _GDIPlus_GraphicsDrawLine($Backbuffer, $pos2[0], $pos[1], $pos2[0], $pos2[1], $hPen);Rechts vertikal
    _GDIPlus_GraphicsDrawLine($Backbuffer, $pos[0], $pos2[1], $pos2[0], $pos2[1], $hPen);Unten horizontal
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    WEnd
    _GDIPlus_GraphicsClear($Backbuffer, 0xFF000000)
    Sleep(10)
    WEnd

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

    Func _Shut()
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_GraphicsDispose($Backbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenCreate($hPen)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Shut

    [/autoit]
  • Das funktioniert leider nur am Anfang, wenn ich was zeichne, dann wird die GUI wieder undurchsichtig.

  • Liegt daran das es doppelt gepuffert ist, ohne geht es:

    Spoiler anzeigen
    [autoit]

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

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

    HotKeySet("{ESC}", "_Shut")
    Opt("GUIOnEventMode", 1)

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

    $hGui = GUICreate("GDI+", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_LAYERED)
    GUISetBkColor(0x000000)
    _WinAPI_SetLayeredWindowAttributes($hGui,0x000000,255)
    GUISetOnEvent(-3, "_Shut")
    GUISetState()

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

    _GDIPlus_Startup()
    Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
    Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphics)
    Global $Backbuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Global $hPen = _GDIPlus_PenCreate(0xFFFF0000, 2)

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

    _GDIPlus_GraphicsClear($Backbuffer)
    Sleep(300)

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

    While 1
    $pos = MouseGetPos()
    While _IsPressed("01")
    $pos2 = MouseGetPos()
    _GDIPlus_GraphicsClear($hGraphics)
    _GDIPlus_GraphicsDrawLine($hGraphics, $pos[0], $pos[1], $pos2[0], $pos[1], $hPen);Oben horizontal
    _GDIPlus_GraphicsDrawLine($hGraphics, $pos[0], $pos[1], $pos[0], $pos2[1], $hPen);Links vertikal
    _GDIPlus_GraphicsDrawLine($hGraphics, $pos2[0], $pos[1], $pos2[0], $pos2[1], $hPen);Rechts vertikal
    _GDIPlus_GraphicsDrawLine($hGraphics, $pos[0], $pos2[1], $pos2[0], $pos2[1], $hPen);Unten horizontal
    ;~ _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0)
    WEnd
    _GDIPlus_GraphicsClear($hGraphics, 0xFF000000)
    Sleep(10)
    WEnd

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

    Func _Shut()
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_GraphicsDispose($Backbuffer)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_PenCreate($hPen)
    _GDIPlus_Shutdown()
    Exit
    EndFunc ;==>_Shut

    [/autoit]