请问怎样让消息框弹出后,5秒后自动关掉!

cooking 2002-07-20 09:40:15
请问怎样让消息框弹出后,5秒后自动关掉!
...全文
296 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jo_yoko 2002-07-20
  • 打赏
  • 举报
回复
我这里有个源程序,你可以看看:

'在表单的声明区中加入以下的声明
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 = "Test Message"

'在表单中加入一个 CommandButton 及一个 Timer 控制项,加入以下程序码:
Private Sub Command1_Click()
Dim nRet As Long
Timer1.Interval = 5000
Timer1.Enabled = True
nRet = MsgBox("若您不回应的话,5 秒后此 MsgBox 会自动关闭", 64, MsgTitle)
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

当 MsgBox 出现 5 秒之后,就会自动关闭了!

注意:此方法是有限制的:
1、当常数设定为 VbAbortRetryIgnore 或 VbYesNo 时,无效!
2、在 Design Time 时,无效,必须 Make EXE 之后才有效!
cooking 2002-07-20
  • 打赏
  • 举报
回复
limengchen(lmc) :能提供个例子吗?小弟没有做过,我加分啦
limengchen 2002-07-20
  • 打赏
  • 举报
回复
不能用windows提供的消息框,你得自己做,在上面放一个timer控件
twtetgso 2002-07-20
  • 打赏
  • 举报
回复
gz

7,757

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧