服务器返回一个模式对话框,只有点击“确定”后,系统才能继续,如何在VB6中写代码自动确定关闭。

解决方案 »

  1.   

    '在表单的声明区中加入以下的声明Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As LongPrivate Const WM_CLOSE = &H10
    Private Const MsgTitle As String = "Test Message"
    '在表单中加入一个 CommandButton 及一个 Timer 控制項,加入以下程序代码:Private Sub Command1_Click()
    Dim nRet As Long
    Timer1.Interval = 3000
    Timer1.Enabled = True
    nRet = MsgBox("若您不回应的話,3 秒后此 MsgBox 会自动关闭", 64, MsgTitle)
    Timer1.Enabled = False
    End SubPrivate 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 之后才有效!