模仿犯小说:VB自动关闭Msgbox - VB - 学习点滴

来源:百度文库 编辑:中财网 时间:2024/05/05 17:38:27
'本代码要测试时请先编译成 .exe 再试'添加 Command1   Timer1Private 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 SubPrivate Sub Timer1_Timer()
    hwnd = FindWindow(vbNullString, MsgTitle)
    Call SendMessage(hwnd, WM_CLOSE, 0, ByVal 0&)
End Sub