Transparenz-UDF

  • Hi!

    Ich hab hier eine UDF zu Transparenz (von Progandy ;) ). Ich komm mit der allerdings nicht ganz klar, bzw sie hat keinen Effekt.

    Spoiler anzeigen
    [autoit]

    #include<WindowsConstants.au3>

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

    $gui = GUICreate("Test", 563, 318, 283, 181, $WS_EX_LAYERED)
    $slidTrans = GUICtrlCreateSlider(10, 70, 200, 30)
    GUICtrlSetLimit($slidTrans, 255, 0)
    GUICtrlSetData(-1, 255)
    GUISetState(@SW_SHOW)

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

    While 1
    _API_SetLayeredWindowAttributes($gui,0x010101,255)
    WEnd


    ;===============================================================================
    ;
    ; 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)

    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    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]

    Kann mir jemand sagen warum das nicht funzt? Was hab ich vergessen?

    fabs

    Einmal editiert, zuletzt von fabs (5. Juli 2008 um 11:43)

  • Mein Ziel ist es durch den Slider die Transparenz regeln zu können. Die GUI krieg ich noch hin ;)

  • hmm....
    da kann ich dir wohl nicht helfen, aber ich kann deine datei ein bissl erbessern, mach ich noch...
    danahc was du amchen willst guck ich ma ob ich das hinkrige...

    MfG

  • Mach es halt z.B. so:

    Spoiler anzeigen
    [autoit]

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

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

    $gui = GUICreate("Test", 563, 318, 283, 181, $WS_EX_LAYERED)
    $slidTrans = GUICtrlCreateSlider(10, 70, 200, 30)
    GUICtrlSetLimit($slidTrans, 255, 0)
    GUICtrlSetData(-1, 255)
    GUISetState(@SW_SHOW)

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

    While 1
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $slidTrans
    WinSetTrans($gui,"",GUICtrlRead($slidTrans) )
    EndSwitch
    WEnd

    [/autoit]

    Grüße
    Stilgar

  • Und hier noch mal dein Quellcode, da war beim $gui = .... ein Parameter zu wenig :)

    Spoiler anzeigen
    [autoit]


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

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

    $gui = GUICreate("Test", 563, 318, 283, 181, -1, $WS_EX_LAYERED) ;<-- Hier muss noch das , -1 rein
    $slidTrans = GUICtrlCreateSlider(10, 70, 200, 30)
    GUICtrlSetLimit($slidTrans, 255, 0)
    GUICtrlSetData(-1, 255)
    GUISetState(@SW_SHOW)
    _API_SetLayeredWindowAttributes($gui,0x8080ff,255)

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

    ;habe hier noch nen bissel hinzugefügt :)
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $slidTrans
    _API_SetLayeredWindowAttributes($gui,0x8080ff,GUICtrlRead($slidTrans))
    EndSwitch
    WEnd

    [/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)

    Local Const $AC_SRC_ALPHA = 1
    Local Const $ULW_ALPHA = 2
    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]

    Mfg
    Jens (McPoldy)

    Twitter: jkroeger

    Denn die Dinge, die wir erst lernen müssen, bevor wir sie tun, lernen wir beim Tun.(Aristoteles)

  • Sie ist schon möglich. Aber eine komplett transparente Farbe und die teilweise Transparenz sind nut mit der UDF möglich. Außerdem kann man damit Layered Windows auch ohne ein Transparenzbild anzeigen.