Transparenter Hintergrung bei GUI

  • Dann arbeite doch mit $WS_EX_LAYERED :)

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #include <WINAPI.au3>

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

    #region - GUI Create
    $gui = GUICreate("trans", 300, 400, -1, -1, -1, $WS_EX_LAYERED)
    GUICtrlCreateLabel("This is text on a transparent Layered GUI",10,10,200,20,-1,$GUI_WS_EX_PARENTDRAG)
    GUICtrlSetTip(-1,"Click label to drag layered window")
    $layButt = GUICtrlCreateButton("Button",10,40,40)
    GUISetBkColor(0xABCDEF)
    _API_SetLayeredWindowAttributes($gui,0x010101)
    GUISetState()
    $guicontrol = GUICreate("ControlGUI", 300, 400, 100, 100)
    $checkTrans = GUICtrlCreateCheckbox("Transparent color 0xABCDEF (Checked) Or 0x010101",10,10)
    $checkBorder = GUICtrlCreateCheckbox("POPUP-Style",10,30)
    GUICtrlCreateLabel("Transparency for Layered GUI",10,50)
    $slidTrans = GUICtrlCreateSlider(10,70,200,30)
    GUICtrlSetLimit($slidTrans,255,0)
    GUICtrlSetData(-1,255)
    GUISetState()
    #endregion

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

    #region - GUI SelectLoop
    While 1
    $extMsg = GUIGetMsg(1)
    $msg = $extMsg[0]
    Switch $extMsg[1]
    Case $guicontrol
    Select
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    Case $msg = $checkTrans Or $msg = $slidTrans

    ; Change Attributes of Trans-Color and Window Transparency

    If BitAND(GUICtrlRead($checkTrans),$GUI_CHECKED) = $GUI_CHECKED Then
    _API_SetLayeredWindowAttributes($gui,0xABCDEF,GUICtrlRead($slidTrans))
    Else
    _API_SetLayeredWindowAttributes($gui,0x010101,GUICtrlRead($slidTrans))
    EndIf

    Case $msg = $checkBorder
    If BitAND(GUICtrlRead($checkBorder),$GUI_CHECKED) = $GUI_CHECKED Then
    GUISetStyle($WS_POPUP,-1,$gui)
    Else
    GUISetStyle($GUI_SS_DEFAULT_GUI,-1,$gui)
    EndIf
    EndSelect
    Case $gui
    Select
    Case $msg = $layButt
    MsgBox(0, '', "Button on layered Window Clicked")
    Case $msg = $GUI_EVENT_CLOSE
    Exit MsgBox(0, '', "Close from Layered GUI")
    EndSelect
    EndSwitch
    WEnd
    #endregion

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

    ;===============================================================================
    ;
    ; Function Name: _API_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-Strucure, 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
    ;
    ;===============================================================================
    ;
    Func _API_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $isColorRef = False)

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

    Local Const $LWA_ALPHA = 0x2
    Local Const $LWA_COLORKEY = 0x1
    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", $LWA_COLORKEY + $LWA_ALPHA)
    Select
    Case @error
    Return SetError(@error,0,0)
    Case $ret[0] = 0
    Return SetError(4,0,0)
    Case Else
    Return 1
    EndSelect
    EndFunc ;==>_API_SetLayeredWindowAttributes

    [/autoit]
  • Die GUI wird transparent, wenn du die Hintergrundfarbe auf die gleiche Farbe setzt wie die, die du in meiner Funktion _API_SetLayeredWindowAttributes angegeben hast :)
    (Und $WS_EX_LAYERED gesetzt ist)
    _API_SetLayeredWindowAttributes ist in meinem vorherigen Post