对于MSGBOX同样是有句柄的,所以你可利用API函数来实现你想的东西
一个是Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
与Public 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 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 Sub Command1_Click()
Dim nRet As Long
Timer1.Interval = 3000
Timer1.Enabled = True
nRet = MsgBox("若您不回應的話,3 秒後此 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 出現 3 秒之後,就會自動關閉了!
注意:此方法的限制說明:
1、當常數設定為 VbAbortRetryIgnore 或 VbYesNo 時,無效!
2、在 Design Time 時,無效,必須 Make EXE 之後才有效!