可以捕捉到另一个程序弹出的MsgBox吗,在程序中选择让msgBox弹出或禁止?

解决方案 »

  1.   

    msgbox上面有两个按钮yes和no,想在用户按yes 或NO之前,自动在程序中按yes或NO,可以做到吗
      

  2.   

    装WH_CBT钩子在它没出来就kill掉
      

  3.   

    可以做到,先找到MSGBOX的HWND,再找BUTTON,再发MOUSEDOWN、MOUSEUP消息。
      

  4.   

    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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Const BM_CLICK = &HF5
    const ts="提示框名"
    const an ="按钮名"Private Sub Timer1_Timer()
        pk = FindWindow(vbNullString, ts)         ,查找窗体,就是警告对话筐
        pp = FindWindowEx(pk, ByVal 0&, "Button", an)  ' 查找指定窗题上的指定button
        SendMessage pp, BM_CLICK, 0, 0                 ’给button发送按下消息
    End Sub
      

  5.   

    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 FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongConst WM_CLOSE = &H10
    Const ts = "提示框名"
    Const an = "按钮名"Private Sub Command1_Click()
        pk = FindWindow(vbNullString, ts)         '查找窗体,就是警告对话筐    SendMessage pk,WM_CLOSE , 0, 0
    End Sub
    这个也可以
      

  6.   

    aspower所说的,要手工去操作,或定时器。如果在wh_cbt中,则系统会返回要建立窗口的句柄,所以不用findWindow
    只是安装wh_cbt钩子后,在调试中很容易导致其它程序崩溃。
      

  7.   

    这是一个自动关闭 USB 设备拔掉时操作系统弹出对话框的例子,放在 Timer 中:Dim TemphWnd As Long
        
        TemphWnd = FindWindow(vbNullString, "不安全的设备删除")
        If TemphWnd Then RetVal = SendMessage(TemphWnd, WM_CLOSE, 0&, 0&)另,需要在声明 API:
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPublic Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Const WM_CLOSE = &H10