检测在另一个应用程序中打开的消息框
我正在 VB.NET 中开发一个 Windows 服务,该服务启动一个执行某些工作的旧应用程序。该服务充当旧应用程序的包装器,允许用户自动执行手动操作。
一切都运行良好,除了旧版应用程序偶尔会显示消息框。当执行此操作时,进程将停止,直到消息框关闭。
由于该服务将在服务器上运行,因此用户不会关闭消息框。
该服务在 System.Diagnostics.Process 中启动旧应用程序。
有没有办法检测我使用 System.Diagnostics.Process 启动的进程是否已显示消息框?有没有办法通过代码关闭消息框?
I am developing a windows service, in VB.NET, that launches a legacy application that performs some work. The service acts as a wrapper around the legacy app allowing users to automate an otherwise manual operation.
Everything is working great, except occasionally the legacy app displays a messagebox. When it does this the process halts until the message box is closed.
As the service will be running on a server there will be no user to close the message box.
The service launches the legacy application in a System.Diagnostics.Process
.
Is there way to detect that a message box has been displayed by a process that I have started using System.Diagnostics.Process
? And is there a way to close the messagebox through code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我还发现 EnumChildWindows 不返回 MessageBox。但我找到了一个网站,向我展示了如何做到这一点。 http://vbcity.com/forums/t/105842.aspx
您想要调用 GetWindow 并传入 GW_ENABLEDPOPUP。它就像一个魅力。感谢斯科特·瓦莱茨科!
I also found that EnumChildWindows does not return the MessageBox. But I found a site that showed me how to do it. http://vbcity.com/forums/t/105842.aspx
You want to call GetWindow passing in GW_ENABLEDPOPUP. It worked like a charm. Thanks to Scott Waletzko!
使用
FindWindow
查找应用程序,使用EnumChildWindows
枚举它的所有子窗口,直到找到消息框(如果消息框不是应用程序主窗口的直接子窗口)我认为您可能必须进行递归调用)。您也许可以跳过
FindWindow
调用,而使用Process
的MainWindowHandle
属性,但我尚未检查这是否有效。Spy++ 是查看所有这些信息的一个好工具,它可以帮助您查看有关正在运行的进程的一些信息。
Use
FindWindow
to find the app, the useEnumChildWindows
to enumerate all it's childwindows until you find the messagebox (if the messagebox isn't a direct child of the main window of the app you might have to have recursive calls I think).You might be able to skip the
FindWindow
call and instead use theMainWindowHandle
property of theProcess
, but I haven't checked if that works.A good tool for looking at all this is Spy++ which can help you see some information you can get hold of about a running process.