怎么让他显示三秒后自动消失?
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Private Const WM_CLOSE = &H10
Private Const MsgTitle As String = "3秒自动消失"
Private Sub Command1_Click()
Dim msg As String
Timer1.Enabled = True
If Compiled Then
msg = "将会消失在 3 秒后。"
Else
msg = "将会消失在 3秒后," & vbCrLf & "必须编译后才能看见效果。"
End If
MsgBox msg, vbOKOnly, MsgTitle
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim hWnd As Long
hWnd = FindWindow(vbNullString, MsgTitle)
Call SendMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
End Sub
Private Function Compiled() As Boolean
On Error GoTo NotCompiled
Debug.Print 1 / 0
Compiled = True
NotCompiled:
End Function
这个必须编译后才可以用的啊
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Private Const WM_CLOSE = &H10
Private Const MsgTitle As String = "3秒自动消失"
Private Sub Command1_Click()
Dim msg As String
Timer1.Enabled = True
If Compiled Then
msg = "将会消失在 3 秒后。"
Else
msg = "将会消失在 3秒后," & vbCrLf & "必须编译后才能看见效果。"
End If
MsgBox msg, vbOKOnly, MsgTitle
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim hWnd As Long
hWnd = FindWindow(vbNullString, MsgTitle)
Call SendMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
End Sub
Private Function Compiled() As Boolean
On Error GoTo NotCompiled
Debug.Print 1 / 0
Compiled = True
NotCompiled:
End Function
这个必须编译后才可以用的啊
全程编译吗?