在 form 中随意放入一些控件 贴入下面代码 运行可看到效果
Const
LWA_COLORKEY
=
&
H1
Const
LWA_ALPHA
=
&
H2
Const
GWL_EXSTYLE
=
(
-
20
)
Const
WS_EX_LAYERED
=
&
H80000
Const
WS_EX_TRANSPARENT
As
Long
=
&
H20
&
Private
Declare
Function
GetWindowLong Lib
"
user32
"
Alias
"
GetWindowLongA
"
(ByVal hWnd
As
Long
, ByVal nIndex
As
Long
)
As
Long
Private
Declare
Function
SetWindowLong Lib
"
user32
"
Alias
"
SetWindowLongA
"
(ByVal hWnd
As
Long
, ByVal nIndex
As
Long
, ByVal dwNewLong
As
Long
)
As
Long
Private
Declare
Function
SetLayeredWindowAttributes Lib
"
user32
"
(ByVal hWnd
As
Long
, ByVal crKey
As
Long
, ByVal bAlpha
As
Byte
, ByVal dwFlags
As
Long
)
As
Long
Private
Sub
Form_Load()
Dim
co
As
Long
'
Show
Me.BackColor
=
RGB
(
255
,
23
,
100
)
co
=
Me.BackColor

Dim
Ret
As
Long
Ret
=
GetWindowLong(Me.hWnd, GWL_EXSTYLE)
Ret
=
Ret
Or
WS_EX_LAYERED
'
Or WS_EX_TRANSPARENT
SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
'
Set the opacity of the layered window to 200
'
SetLayeredWindowAttributes Me.hWnd, 0, 200, LWA_ALPHA
SetLayeredWindowAttributes Me.hWnd, co,
200
,
&
H1
End Sub
