【已解决】关于_WinAPI_GetLayeredWindowAttributes的透明度设置问题
本帖最后由 anythinging 于 2019-10-21 22:23 编辑本地$ hGui = GUICreate(“ trans”,300,400,-1,-1,-1,$ WS_EX_LAYERED)
GUICtrlCreateLabel(“这是透明分层GUI上的文本” ,10,10,200,20 ,-1, $ GUI_WS_EX_PARENTDRAG)
$ iTransColor = 65793
$ iAlpha = 150
本地$ iInfo = _WinAPI_GetLayeredWindowAttributes($ hGui,$ iTransColor,$ iAlpha)
这个是从udf 中下载的实例,是用一个托动的方式调节方式的,对初学者来讲有难度。
请大神指点,怎么设置$ iAlpha值来简单实现?越简单越好,感谢!
anythinging 发表于 2019-10-21 21:56
管用管用,而且非常容易理解,比示例好多了。感谢指点!
想问下如果实现背景色透明,就得用示例的代码了 ...
#include <WindowsConstants.au3>
#include <WinAPI.au3>
Local $gui = GUICreate("trans", 300, 400, -1, -1, -1, $WS_EX_LAYERED)
Local $layButt = GUICtrlCreateButton("Button", 10, 40, 40)
GUISetBkColor(0xABCDEF)
_WinAPI_SetLayeredWindowAttributes($gui, 0xABCDEF, 200)
GUISetState()
While GUIGetMsg() <> -3
WEnd 你这个是获取,设置是 …Set…
没特殊要求 WinSetTrans("标题", "文本", 透明度) 感谢回复!
这个是示例
#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
Switch $extMsg
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
实现透明度是这句实现的,用msgbox看了$ iAlpha的值,大至是1-255,但手动设置$ iAlpha值 不生效,它好象是个其它类型的值,不知如何手动设置它的值
本地$ iInfo = _WinAPI_GetLayeredWindowAttributes($ hGui,$ iTransColor,$ iAlpha) 舍近求远,给你说了试了没?
$gui = GUICreate("trans", 300, 400)
GUICtrlCreateButton("Button", 10, 40, 40)
WinSetTrans($gui, '', 150)
GUISetState()
While GUIGetMsg() <> -3
WEnd afan 发表于 2019-10-21 20:10
舍近求远,给你说了试了没?
管用管用,而且非常容易理解,比示例好多了。感谢指点!
想问下如果实现背景色透明,就得用示例的代码了吧? 感谢指点!透明的都示例理解起来比较容易,看来透明还是得用示例的方法。
页:
[1]