关于VB 淡出淡入的一个问题
来源:百度知道 编辑:UC知道 时间:2024/08/22 11:07:16
FORM2的代码如下
Option Explicit
Private Const LWA_ALPHA = &H2
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_COLORKEY = &H1
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
Dim Color%, M%
Private Sub Form_Load()
Dim rtn&
Color = 5
M = 5
Timer1.Interval = 5
rtn = GetWindowLong(Me.hWnd, GWL_EX
楼上的代码是直接结束掉了程序呵,如果是想关掉form2,而不结束程序,应该增加一个bool变量,来决定是否完全淡出,并可以结束程序了,我添加了一个变量b,启动时为false, 在第1次unload me时,激活timer,并开始淡出过程, 完成淡出后,让变量b为true,再次unload me,此时可以正常退出form2了
完整代码:
Option Explicit
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 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
Dim Color%, M%, b As Boolean
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Fo