函数参考


_WinAPI_SetLayeredWindowAttributes

设置分层窗口属性

#Include <WinAPI.au3>
_WinAPI_SetLayeredWindowAttributes($hWnd, $i_transcolor [, $Transparency = 255 [, $dwFlags = 0x03 [, $isColorRef = False]]])

参数

$hwnd 工作 GUI 的句柄
$i_transcolor 透明色
$Transparency [可选参数] 设置透明度的 GUI
$dwFlags [可选参数] Flags.
$isColorRef [可选参数] 如为 True, $i_transcolor is a COLORREF( 0x00bbggrr ), 否则为 RGB 颜色

返回值

成功: 返回 1
失败: 返回 0
@error: 4 - 函数不成功 - @extended 设置为 _WinAPI_GetLastErrorMessage 以获取其它信息

注意/说明

None.

相关

_WinAPI_GetLayeredWindowAttributes, _WinAPI_GetLastError

详情参考

在MSDN中搜索


示例/演示


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

Local $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")
Local $layButt = GUICtrlCreateButton("Button", 10, 40, 40)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($gui, 0x010101)
GUISetState()

Local $guicontrol = GUICreate("ControlGUI", 300, 400, 100, 100)
Local $checkTrans = GUICtrlCreateCheckbox("Transparent color 0xABCDEF (Checked) Or 0x010101", 10, 10)
Local $checkBorder = GUICtrlCreateCheckbox("POPUP-Style", 10, 30)
GUICtrlCreateLabel("Transparency for Layered GUI", 10, 50)
Local $slidTrans = GUICtrlCreateSlider(10, 70, 200, 30)
GUICtrlSetLimit($slidTrans, 255, 0)
GUICtrlSetData(-1, 255)
GUISetState()

While 1
    Local $extMsg = GUIGetMsg(1)
    Local $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
                        _WinAPI_SetLayeredWindowAttributes($gui, 0xABCDEF, GUICtrlRead($slidTrans))
                    Else
                        _WinAPI_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
                    Local $transcolor, $alpha
                    Local $info = _WinAPI_GetLayeredWindowAttributes($gui, $transcolor, $alpha)
                    MsgBox(4096, 'Layered GUI', "Button on layered Window Clicked" & @CRLF & "Information about this window: " & @CRLF & _
                            "Transparent Color: " & $transcolor & @CRLF & _
                            "Alpha Value: " & $alpha & @CRLF & _
                            "LWA_COLORKEY: " & (BitAND($info, $LWA_COLORKEY) = $LWA_COLORKEY) & @CRLF & _
                            "LWA_ALPHA: " & (BitAND($info, $LWA_ALPHA) = $LWA_ALPHA))
                Case $msg = $GUI_EVENT_CLOSE
                    Exit MsgBox(4096, '', "Close from Layered GUI")
            EndSelect
    EndSwitch
WEnd