Msgbox的使用方法相信很多人都知道,但想实现一下定时自动关闭的消息提示框,相信很多人都没有尝试过
下面就教一下大家:
先建立一个模块:
Option Compare Database
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Public Const NV_CLOSEMSGBOX As Long = &H5000&
Public Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
KillTimer hWnd, idEvent
Select Case idEvent
Case NV_CLOSEMSGBOX
Dim hMessageBox As Long
hMessageBox = FindWindow("#32770", "提示")
If hMessageBox Then
Call SetForegroundWindow(hMessageBox)
SendKeys "{enter}"
End If
End Select
End Sub
然后在你需要的窗体中调用:
SetTimer hWnd, NV_CLOSEMSGBOX, 2000, AddressOf TimerProc '设置关闭的时间
MsgBox "我是一个能自动关闭的msgbox", vbOKCancel, "提示"
显示效果: