在VB中如何做到使一个msgbox的提示信息只弹出来0.5秒(大概)的时间就自动消失呢?

来源:百度知道 编辑:UC知道 时间:2024/05/26 10:01:27
请哪位高手能简单的说下部分代码!
我想应该用到timer控件,注意是一定是自动消失,不用人点的
(注:程序的其它的什么返回信息什么的,不用过多的考虑,我自己再弄)

msgbox本身没有这样的功能,要想实现只能借用api函数控制鼠标或者键盘了。

'本代码要测试时请先编译成 .exe 再试
'添加 Command1 Timer1

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
Const WM_CLOSE = &H10
Const MsgTitle As String = "Test Message"
Dim Rtn&, hwnd&
Private Sub Command1_Click()
Timer1.Interval = 3000
Timer1.Enabled = True
Rtn = MsgBox("若您不回应的话,3 秒后此 MsgBox 会自动关闭", 64, MsgTitle)
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
hwnd = FindWindow(vbNullString, MsgTitle)
Call SendMessage(hwnd, WM_CLOSE, 0, ByVal 0&)
End Sub

可以用添加一个窗体做的像MsgBox 再在上面放一个Timer就OK啊