VB启动窗口渐变效果

| |
[不指定 2019/03/18 14:24 | by admin ]
建立一个Timer1 即可实现启动窗口渐变效果

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 Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1

Private Sub Form_Load()
SetWinAlpha 0
Timer1.Interval = 30
Timer1.Enabled = True
End Sub

Sub SetWinAlpha(a As Byte)
SetWindowLong Me.HWnd, GWL_EXSTYLE, GetWindowLong(Me.HWnd, GWL_EXSTYLE) Or WS_EX_LAYERED
SetLayeredWindowAttributes Me.HWnd, 0, a, LWA_ALPHA
End Sub

Private Sub Timer1_Timer()
Static a As Byte
If a >= 255 Then
    SetWinAlpha 255
    Timer1.Enabled = False
Else
    SetWinAlpha a
    a = a + 5
End If
End Sub
程序源码 | 评论(0) | 引用(0) | 阅读(238)