_DrawTransparent

  • Hiho,

    Anleitung

    Spoiler anzeigen
    [autoit]

    ;===============================================================================
    ;
    ; Function Name:
    ; _DrawTransparentEllipse
    ; Description:: Let you draw a transparent Ellipse
    ; Parameter(s):
    ; $hwnd - Handle of GUI to work on
    ; $x - Postion x of the Ellipse
    ; $y - Postion y of the Ellipse
    ; $w - Width of the Ellipse
    ; $h - Height of the Ellipse, If w=h it will be a circle.
    ; $Transparency - Set Transparancy of GUI ( optional )
    ; Requirement(s): The Styles $WS_EX_COMPOSITED $WS_EX_LAYERED
    ; Return Value(s): Returns a windows handle.
    ; Author(s): Greek, martin
    ; Example : Yes
    ;===============================================================================

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

    ;===============================================================================
    ;
    ; Function Name:
    ; _DrawTransparentRect
    ; Description:: Let you draw a transparent Rect
    ; Parameter(s):
    ; $hwnd - Handle of GUI to work on
    ; $x - Postion x of the Rect
    ; $y - Postion y of the Rect
    ; $w - Width of the Rect
    ; $h - Height of the Rect, If w=h it will be a square.
    ; $Transparency - Set Transparancy of GUI ( optional )
    ; Requirement(s): The Styles $WS_EX_COMPOSITED $WS_EX_LAYERED
    ; Return Value(s): Returns a windows handle.
    ; Author(s): Greek, martin
    ;===============================================================================

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

    ;===============================================================================
    ;
    ; Function Name:
    ; _DrawTransparentLine
    ; Description:: Let you draw a transparent Line
    ; Lines must be drawed first and can't used dynamical!!.
    ; Parameter(s):
    ; $hwnd - Handle of GUI to work on
    ; $x - Postion x of the Line
    ; $y - Postion y of the Line
    ; $length - length of the Line
    ; $course - course of the Line
    ; $pensize - The pensize, default is 2 ( optional )
    ; $Transparency - Set Transparancy of GUI ( optional )
    ; Requirement(s): Layered Windows ( $WS_EX_LAYERED )
    ; Return Value(s): ControlID of the Form
    ; Author(s): Greek, martin
    ;===============================================================================

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

    ;===============================================================================
    ;
    ; Function Name:
    ; _DeletTransparentForm
    ; Description:: Delet the Form
    ; Parameter(s):
    ; $Form - controlID/handle of the Form
    ; Return Value(s): Success: Returns 1.
    ; Failure: Returns 0.
    ; Author(s): Greek, martin
    ;===============================================================================

    [/autoit]

    Include

    Spoiler anzeigen
    [autoit]

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

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

    Global Const $WS_EX_COMPOSITED = 0x2000000

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

    Func _DrawTransparentEllipse($hwnd, $x,$y,$w,$h,$Transparency=255)
    $Child=GUICreate ( "", $w, $h, $x, $y, $WS_CHILD, -1, $hwnd )
    _WinAPI_SetLayeredWindowAttributes($hwnd, 0xABCDEF, $Transparency)
    GUISetBkColor ( 0xABCDEF, $Child )
    _GuiRoundCorners ( $Child, 0, 0, $w, $h)
    GUISetState()
    Return $Child
    EndFunc

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

    Func _DeletTransparentForm ( $Form )
    If IsHWnd($Form) Then
    $a=GUIDelete($Form)
    Return $a
    Else
    $b=GUICtrlDelete($Form)
    Return $b
    EndIf
    EndFunc

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

    Func _DrawTransparentRect($hwnd, $x,$y,$w,$h,$Transparency=255)
    $Child=GUICreate ( "", $w, $h, $x, $y, $WS_CHILD, -1, $hwnd )
    _WinAPI_SetLayeredWindowAttributes($hwnd, 0xABCDEF, $Transparency)
    GUISetBkColor ( 0xABCDEF, $Child )
    GUISetState()
    Return $Child
    EndFunc

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

    Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    ; progandy
    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] [autoit][/autoit] [autoit]

    Func _WinAPI_GetLastError()
    Local $aResult

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

    $aResult = DllCall("Kernel32.dll", "int", "GetLastError")
    If @error Then Return SetError(@error, 0, 0)
    Return $aResult[0]
    EndFunc ;==>_WinAPI_GetLastError

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

    Func _GuiRoundCorners($hWnd, $x1, $y1, $x3, $y3)
    Local $pos, $ret, $ret2
    $pos = WinGetPos($hWnd)
    $ret = DllCall('gdi32.dll', 'long', 'CreateRoundRectRgn', 'long', $x1, 'long', $y1, 'long', $pos[2], 'long', $pos[3], 'long', $x3, 'long', $y3)
    If $ret[0] Then
    $ret2 = DllCall('user32.dll', 'long', 'SetWindowRgn', 'hwnd', $hWnd, 'long', $ret[0], 'int', 1)
    If $ret2[0] Then
    Return 1
    Else
    Return 0
    EndIf
    Else
    Return 0
    EndIf
    EndFunc

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

    Func _DrawTransparentLine($hwnd, $X,$Y,$length,$course,$pensize=2,$Transparency=255)
    _WinAPI_SetLayeredWindowAttributes($hwnd, 0xABCDEF, $Transparency)
    $g1=GUICtrlCreateGraphic($X,$Y,0,0)
    GUICtrlSetGraphic($g1, $GUI_GR_PENSIZE, $pensize )
    GUICtrlSetGraphic($g1, $GUI_GR_COLOR,0xABCDEF, 0xABCDEF)
    GUICtrlSetGraphic($g1, $GUI_GR_LINE, $length, $course)
    GUICtrlSetGraphic($g1, $GUI_GR_REFRESH)
    GUICtrlSetGraphic($g1, $GUI_GR_LINE, 1, 1)
    Return $g1
    EndFunc

    [/autoit]

    Beispiel

    Spoiler anzeigen
    [autoit]

    #include <DrawTransparent.au3>

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

    Global $Count=300
    Global $Ellipse[$Count], $j=1

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

    $myGui=GUICreate ( "dynamic transparent test", @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR ( $WS_EX_TOPMOST, $WS_EX_COMPOSITED, $WS_EX_LAYERED ) )
    GUISetBkColor ( 0x000000 )
    GUISetState ()

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

    $Ellipse[0]=_DrawTransparentEllipse( $myGui, @DesktopWidth/2-200, @DesktopHeight/2-200, 400, 300 )

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

    For $i=1 To $Count-1 Step +1
    $Ellipse[$i]=_DrawTransparentEllipse ( $myGui, @DesktopWidth/2-200-$i, @DesktopHeight/2-200, 400+$j, 300 )
    GUIDelete ( $Ellipse[$i-1] )
    $j+=2
    Next

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

    While 1
    $msg=GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
    Exit
    EndSwitch
    WEnd

    [/autoit]

    Edit: Update 2, Rect und Ellipse jetzt auch dynamisch!

    8 Mal editiert, zuletzt von Greek (26. April 2009 um 14:46)

  • Find ich sehr schön ^^ Mal ein paar Funktionen, die die Transparents schon eingebaut haben...

    Weiter so :)

    Zitat

    [Heute, 11:39] Raupi: Soll ich es dir machen?
    [Heute, 11:47] BugFix: "Soll ich es dir machen? " - also Raupi !! bitte nicht so öffentlich :rofl:

    Zitat

    [Heute, 11:51] BugFix: und ich werde es mir jetzt machen - das Mittagessen :P

    AMsg UDF v1.00.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%
    OwnStyle UDF Version 1.10.00 IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII 100%