自动关闭一个MessageBox [英] Closing a MessageBox automatically

查看:316
本文介绍了自动关闭一个MessageBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方加密库,如果密钥创建失败,这可能会创建一个消息框。该故障可以通过坏随机数生成或其他稀有引起的,而且在大多数情况下,试图再次将导致成功。我的code将决定它失败之前尝试密钥创建多达三次。

I have a third party encryption library, which may create a MessageBox if key creation fails. The failure can be caused by bad random number generation or other rarities, and in most cases, trying again will result in success. My code will attempt key creation up to three times before deciding it failed.

现在,问题是,该方案可以与自动化使用。如果自动化过程中创建一个MessageBox,它会永远阻止的过程中,因为有没有人点击确定按钮。

Now, the issue is that the program may be used with automation. If a MessageBox is created during automation, it will block the process forever, because there's nobody to click the 'OK' button.

有谁知道的方式创造了这个消息框时捕获和自动关闭呢?

Does anyone know of a way to catch when this message box is created and automatically close it?

任何事情都是公平的游戏,只要它不是东西,这将使安全套件生气。这意味着,没有挂钩或code隧道。

Anything is fair game, as long as it's not something that will make security suites angry. This means no hooking or code tunneling.

总之,我需要的是创建一个消息时,赶上并关闭它。在MessageBox的创作是我的控制之外。修改code在运行时是不能接受的。

In summary, I need to catch when a MessageBox is created and close it. The MessageBox's creation is outside of my control. Modifying the code at runtime is not acceptable.

另外,我注意到还有其他一些类似的问题,但他们不具有相同的要求。

Also, I've noticed there are some other similar questions, but they don't have the same requirements.

编辑:附加注释,我可以找到通过通过所有窗口搜索消息框,直到我找到一个具有匹配的标题,然后发送一个WM_CLOSE消息,但我不认为这是一个很好的解决方案。我也不能保证消息框已/将显示,要不了多久我的电话后就会显示出来。它可以即时显示,后来可以显示1200毫秒,或者它可能根本不显示。

Additional note, I can find the message box via searching through all windows until I find one with a matching title and then send it a WM_CLOSE message, but I don't think this is a great solution. I also have no guarantee that the message box has been/will be displayed, or how long after my call it will be displayed. It could display instantly, it could display 1200 ms later, or it could not display at all.

推荐答案

在开始加密过程之前才安装 WH_CBT ,并在其的回调观看的n code HCBT_CREATEWND 。如果你得到一个匹配的类名('#32770(对话)'?)和匹配的标题无论是从回调返回一个非零值,或者如果不工作发布 WM_CLOSE (或 BM_CLICK 来相关的按钮,如果选择一个选项是必需的)。不与每一个可能的对话框应用程序弹出搞乱过程后卸载钩子。

Just before you begin the encryption process, install a WH_CBT hook, and in its callback watch for an nCode of HCBT_CREATEWND. If you get a matching class name ('#32770 (Dialog)' ?) and a matching title either return a nonzero value from the callback, or if that doesn't work post a WM_CLOSE (or a BM_CLICK to a relevant button if selecting an option is necessary). Uninstall the hook after the process for not messing with every possible dialog your application pops up.

这篇关于自动关闭一个MessageBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆