本文主要是介绍利用Timer实现窗体淡入淡出的效果,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
'在窗口上添加一个Timer,默认设置
'代码如下:
Option Explicit
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
Dim StepCount As Long, Toggle As Boolean
Private Sub Lucency(hwnd As Long, B As Long, LWA As Boolean)
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
Call SetWindowLong(hwnd, GWL_EXSTYLE, rtn)
If LWA And B > 255 Or B < 0 Then Exit Sub
Call SetLayeredWindowAttributes(hwnd, IIf(LWA <> True, B, 0), IIf(LWA, B, 0), IIf(LWA, LWA_ALPHA, LWA_COLORKEY))
End Sub
Private Sub Form_Load()
Timer1.Interval = 1
Toggle = True
Call Lucency(Me.hwnd, 0, True)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
Toggle = False
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If Toggle Then
If StepCount < 255 Then StepCount = StepCount + 5 Else Timer1.Enabled = False
Else
If StepCount > 0 Then StepCount = StepCount - 5 Else End
End If
Call Lucency(Me.hwnd, StepCount, True)
End Sub
这篇关于利用Timer实现窗体淡入淡出的效果的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!