PNG als Gui (Transparent)

  • Hallo,

    ich möchte mir gerne eine Gui mit einer transparenten PNG Grafik machen.
    Die Grafik wird gezeigt.

    Zitat

    Wie kann man die Gui transparent machen,
    aber die Grafik mit den Objekten zeigen?

    [autoit]


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

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

    Global $hGUI, $hImage, $hGraphic, $hImage1

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

    ; Create GUI
    $hGUI = GUICreate("PNG", 500, 600)

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

    WinSetTrans("PNG","",170); hier wird die Transparenz eingestellt
    ; Load PNG image
    _GDIPlus_StartUp()
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir& "\Trans.png"); hier ist meine PNG Grafik
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

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

    GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
    GUISetState()

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

    ; Loop until user exits
    do
    until GUIGetMsg() = $GUI_EVENT_CLOSE

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

    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ShutDown()

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

    ; Draw PNG image
    Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
    EndFunc

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

    Grüße
    Ilse ;)

    Einmal editiert, zuletzt von Ilse (17. November 2010 um 11:23)

  • hm... ich habe jetzt versucht
    das Script von Bugfix mit Png Bild zu integrieren
    hat leider nichts gebracht.

    ...bei diesem Script gibt es noch folgende Probleme:

    Meine Objekte sind im Hintergrund, wie bekomme ich die nach vorne?

    [autoit]


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

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

    Global $hGUI, $hImage, $hGraphic, $hImage1

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

    ; Create GUI
    $hGUI = GUICreate("Show PNG", 350, 550,-1,-1, BitOR($WS_POPUP,$DS_MODALFRAME,$WS_EX_LAYERED),$WS_EX_ACCEPTFILES);,$DS_SETFOREGROUND))

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

    $Input1 = GUICtrlCreateInput("Input1", 156, 232, 121, 21)
    $Input2 = GUICtrlCreateInput("Input2", 156, 256, 121, 21)
    $Input3 = GUICtrlCreateInput("Input3", 156, 280, 121, 21)
    $Slider1 = GUICtrlCreateSlider(128, 312, 150, 45)
    $Button1 = GUICtrlCreateButton("Start", 208, 376, 75, 25)
    ; Load PNG image
    _GDIPlus_StartUp()
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir& "\Trans.png")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)

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

    WinSetTrans("Show PNG","",240)
    ;GUICtrlSetState(-1, $GUI_DISABLE)

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

    GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
    GUISetState()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    exit

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

    EndSwitch
    WEnd
    ; Loop until user exits
    do
    until GUIGetMsg() = $GUI_EVENT_CLOSE

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

    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ShutDown()

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

    ; Draw PNG image
    Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_UPDATENOW)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, $RDW_VALIDATE)
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit]

    Konnte mit GUICtrlSetState(-1, $GUI_DISABLE) die Objekte nicht nach vorne bekommen.
    Bin auch mit WinSetTrans leider nicht ans Ziel gekommen...

    habe das noch gefunden,
    läuft aber nicht: Fehlermeldung

    [autoit]


    #include <WindowsConstants.au3>

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

    $Parent = GUICreate("BackGround",200,200)
    GUICtrlCreatePic("C:\WINDOWS\Zapotek.bmp",0,0,200,200)
    GUISetState()
    WinSetTrans($Parent,"",150)

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

    $gui = GUICreate("Child",200,200,0,0,$WS_POPUP,$WS_EX_LAYERED+$WS_EX_MDICHILD,$Parent)
    GUISetBkColor(0x010203)
    _WinAPI_SetLayeredWindowAttributes($gui,0x010203)
    GUICtrlCreateLabel("Es ist transparent ;)",10,10,90,20)
    $butt = GUICtrlCreateButton("OKOKOK",30,40,90,30)

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

    GUISetState()

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

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    Case $butt
    MsgBox(0, '', "Button")
    EndSwitch
    WEnd
    ;===============================================================================
    ;
    ; Function Name: _WinAPI_SetLayeredWindowAttributes
    ; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
    ; Parameter(s):
    ; $hwnd - Handle of GUI to work on
    ; $i_transcolor - Transparent color
    ; $Transparency - Set Transparancy of GUI
    ; $isColorRef - If True, $i_transcolor is a COLORREF( 0x00bbggrr ), else an RGB-Color
    ; Requirement(s): Layered Windows
    ; Return Value(s): Success: 1
    ; Error: 0
    ; @error: 1 to 3 - Error from DllCall
    ; @error: 4 - Function did not succeed - use
    ; _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
    ; Author(s): Prog@ndy
    ;
    ; Link : @@MsdnLink@@ SetLayeredWindowAttributes
    ; Example : Yes
    ;===============================================================================
    ;
    Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
    If Not $isColorRef Then
    $i_transcolor = Hex(String($i_transcolor), 6)
    $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
    Case @error
    Return SetError(@error, 0, 0)
    Case $Ret[0] = 0
    Return SetError(4, _WinAPI_GetLastError(), 0)
    Case Else
    Return 1
    EndSelect
    EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

    [/autoit]

    huh...mache mal ein Päusschen
    hoffe Ihr habt ne Idee

    Grüße
    Ilse ;)

    3 Mal editiert, zuletzt von Ilse (16. November 2010 um 11:42)

  • Probiere das mal:

    Spoiler anzeigen
    [autoit]


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

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

    Global $hGUI, $hImage, $hGraphic, $hImage
    Global Const $SC_DRAGMOVE = 0xF012

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

    ; Create GUI
    $hGUI = GUICreate("Show PNG", 350, 550, -1, -1, $WS_POPUP, $WS_EX_LAYERED + $WS_EX_TOPMOST)
    GUISetBkColor(0x01, $hGUI)
    GUISetState()
    _WinAPI_SetLayeredWindowAttributes($hGUI, 0x01, 0xFF, 3)

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

    ; Load PNG image
    _GDIPlus_StartUp()
    $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir& "\Trans.png")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)

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

    $Input1 = GUICtrlCreateInput("Input1", 156, 232, 121, 21)
    $Input2 = GUICtrlCreateInput("Input2", 156, 256, 121, 21)
    $Input3 = GUICtrlCreateInput("Input3", 156, 280, 121, 21)
    $Slider1 = GUICtrlCreateSlider(128, 312, 150, 45)
    $Button1 = GUICtrlCreateButton("Start", 208, 376, 75, 25)

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

    GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    ExitLoop
    Case $Button1
    ExitLoop
    Case $GUI_EVENT_PRIMARYDOWN
    _SendMessage($hGUI, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0)
    EndSwitch
    WEnd

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

    ; Clean up resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_ShutDown()
    Exit

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

    ; Draw PNG image
    Func MY_WM_PAINT($hWnd, $Msg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hImage, 0, 0)
    _WinAPI_RedrawWindow($hGUI, 0, 0, 1)
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯