窗体淡入淡出效果:
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Boolean
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 GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_EXSTYLE = -20
Private Const WS_EX_LAYERED = &H80000
Private Const LWA_ALPHA = &H2
Private Sub Form_Load()
SetWindowLong Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
Me.Show
lwa_FadeIn Me.hWnd, 1
End Sub
Private Sub Form_Unload(Cancel As Integer)
lwa_FadeOut Me.hWnd, 1
End
End Sub
Private Sub lwa_FadeIn(ByVal hWnd As Long, Optional ByVal iStep As Integer = 1)
Dim bAlpha As Integer
bAlpha = 0
While bAlpha < 255
If bAlpha > 255 Then bAlpha = 255
SetLayeredWindowAttributes hWnd, 0, bAlpha, LWA_ALPHA
DoEvents
bAlpha = bAlpha + iStep
Wend
End Sub
Private Sub lwa_FadeOut(ByVal hWnd As Long, Optional ByVal iStep As Integer = 1)
Dim bAlpha As Integer
bAlpha = 255
While bAlpha > 0
If bAlpha < 0 Then bAlpha = 0
SetLayeredWindowAttributes hWnd, 0, bAlpha, LWA_ALPHA
DoEvents
bAlpha = bAlpha - iStep
Wend
End Sub