如何捕获应用程序的弹出消息框 [英] How do I catch application's pop-up message box
问题描述
我必须使用VB.Net自动执行Windows应用程序(无API)的重复任务。
我所做的是模拟通常完成的击键用户。
我正在使用System.Threading,并使用新进程启动应用程序。
我的问题是,这个应用程序在任务时弹出一个消息框已完成,此消息框确定禁用主应用程序窗口,因此我需要知道何时显示此消息框以模拟ENTER键击并继续执行下一个任务。
以下是我的代码示例:
Hi,
I have to automate repetitive tasks of a windows application (no API), using VB.Net.
What I did is simulate key strokes usually done by user.
I'm using System.Threading, and initiating the application using a new process.
My PROBLEM is, that this app pops a message box when a task is done, and this message box sure disables the main app window, so I need to know when this message box is displayed to simulate the "ENTER" key stroke and proceed to next task.
Here is a sample of my code:
Imports System.Threading
Public Class Form1
Dim a As New Process
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
a.StartInfo.FileName = "C:\Program Files (x86)\CE\CE.exe"
a.Start()
AppActivate(a.Id)
For i = 1 To CInt(txt.Text)
DoTask()
Next
End Sub
Private Sub DoTask()
Thread.Sleep(1000)
SendKeys.SendWait("^(N)")
Thread.Sleep(500)
SendKeys.SendWait("{ENTER}")
Thread.Sleep(500)
SendKeys.SendWait("new check")
Thread.Sleep(500)
SendKeys.SendWait("{ENTER}")
Do While True
'Here I want to wait until a message box pops up by the application
'If message box displayed then exit do
Loop
SendKeys.SendWait("{ENTER}")
End Sub
End Class
我希望你能帮我解决这个问题,
提前谢谢。
I hope you can help me with this issue,
thanks in advance.
推荐答案
你将得到一份所有开放的清单机器上的窗口,等待弹出消息框并在列表中。然后您可以选择它并发送回车键以关闭它。
只需尝试谷歌搜索vb.net枚举打开的窗口,你会发现许多代码示例。
-Pete
You'll have get a list of all the open windows on the machine, and wait for the message box to pop up and be in the list. Then you can select it and send an enter key to close it.
Just try Googling "vb.net enumerate open windows" and you'll find many code examples.
-Pete
这篇关于如何捕获应用程序的弹出消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!