小小鸭

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
'添加 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
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Const WM_CLOSE = &H10
Const MsgTitle As String = "Test Message"
Dim testhwnd&
Private Sub Command1_Click()
   Timer1.Interval = 3000: Timer1.Enabled = True
   Call MessageBox(Me.hwnd, "若您不回应的话,3 秒后此 MsgBox 会自动关闭", MsgTitle, 64)
   Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
   testhwnd = FindWindow(vbNullString, MsgTitle)
   If testhwnd > 0 Then Call SendMessage(testhwnd, WM_CLOSE, 0, ByVal 0&)
End Sub

  

posted on 2012-06-29 16:31  小小鸭  阅读(718)  评论(0编辑  收藏  举报