2015年4月20日 星期一

VB6 - 程式淡出與淡入


淡出是等於關閉程式時不會直接關閉,會慢慢減少透明度
淡入是等於開啟程式時不會直接彈出,會慢慢增加透明度





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 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 Const WS_EX_LAYERED = &H80000
Private Const GWL_EXSTYLE = (-20)
Private Const LWA_ALPHA = &H2
Private Const LWA_COLORKEY = &H1
Private Const GWL_STYLE = (-16)
Dim Value As Long ' 控制透明度的變量


Private Sub Form_Load()
Dim TempLng As Long
Dim rtn As Long
Value = 0 '預設透明度為0
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 1, Value, LWA_ALPHA
End Sub


Private Sub Timer1_Timer() 'Timer1預設Enabled為 True
Dim TempLng As Long
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 1, Value, LWA_ALPHA
Value = Val(Value) + 5 '透明度每次+5的+上
If Value = 255 Then Timer1 = False '透明度最多是255 這裏是判斷 如果Value到了255就關閉
Timer1
End Sub


Private Sub Form_Unload(Cancel As Integer) '操作關閉事件
Timer2.Enabled = True '開啟Timer2 操作淡出事件
Cancel = 1 '令關閉無效,防止表單直接關閉
End Sub


Private Sub Timer2_Timer()
Dim TempLng As Long
Dim rtn As Long
rtn = GetWindowLong(hwnd, GWL_EXSTYLE)
rtn = rtn Or WS_EX_LAYERED
SetWindowLong hwnd, GWL_EXSTYLE, rtn
SetLayeredWindowAttributes hwnd, 1, Value, LWA_ALPHA
Value = Val(Value) - 5 '透明度每次-5
If Value = 0 Then End ' 如果Value的數值等於0就結束表單
End Sub

沒有留言:

張貼留言

找東西嗎?來這搜尋看看吧!

閱讀前,請先點擊廣告,支持作者

點擊廣告,支持作者