怎么让他显示三秒后自动消失?
怎么让他显示三秒后自动消失?
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
这个必须编译后才可以用的啊
全程编译吗?
你运行就知道了!直接生成exe就可以了!
我试了
除了vbAbortRetryIgnore和vbYesNo之外其他的都可以在设定的时间到时消失
这2个为什么不行