模块中
Option Explicit
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As _
Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
Public Transparency As Integer
Const SWP_NOACTIVATE = 3
Const WS_EX_LAYERED = &H80000
Const GWL_EXSTYLE = (-20)
Const LWA_ALPHA = &H2
Const LWA_COLORKEY = &H1
Sub Translucence(frm As Form)
Dim rtn As Long
rtn = GetWindowLong(frm.hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong frm.hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes frm.hwnd, 0, Transparency, LWA_ALPHA
End Sub
'窗体代码
Private Sub Slider1_Scroll() '用一个slider来控制透明度
Slider1.Min = 0
Slider1.Max = 155
Transparency = 255 - Slider1.Value
Translucence Me
End Sub