如何禁用然后启用消息框中的“重试”按钮?

发布于 2024-07-06 23:43:04 字数 192 浏览 7 评论 0原文

我有以下非托管 C++ 代码:

MessageBox( NULL, strMessage, "Cool Product", MB_RETRYCANCEL | MB_ICONEXCLAMATION);

我想禁用 RETRY 按钮 10 秒(例如),然后启用它。

我怎样才能做到这一点?

I have the following unmanaged C++ code:

MessageBox( NULL, strMessage, "Cool Product", MB_RETRYCANCEL | MB_ICONEXCLAMATION);

I want to disable the RETRY button for 10 seconds (for example), then enable it.

How can I do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

蓝颜夕 2024-07-13 23:43:04

就像 @ ffpf 说,您需要使用 MFC、ATL、原始 Win32 等创建自己的对话框来执行此操作。

然后创建一个计时器来启用和禁用该按钮。

Like @ffpf says, you need to make your own dialog to do this, using MFC, ATL, raw Win32, etc.

Then create a timer that would enable and disable the button.

或十年 2024-07-13 23:43:04

您不能直接操作 MessageBox 控件,但可以使用 hack。 在显示对话框之前安装 WH_CBT 挂钩并处理 HCBT_ACTIVATE 事件。 这将为您提供消息框的 HWND,以便您可以对它执行任何您想要的操作(子类化它、管理其按钮并设置计时器)。

您可以在 James Brown 的网站中找到带有演示代码的自定义 MessageBox 教程。

You cannot directly manipulate the MessageBox controls, but you can use a hack. Install a WH_CBT hook just before displaying the dialog and handle the HCBT_ACTIVATE event. This will give you the HWND of the message box, so that you can do whatever you want with it (subclass it, manage its buttons and set a timer).

You can find a Custom MessageBox tutorial with demo code in James Brown's site.

风启觞 2024-07-13 23:43:04

对于标准的 MessageBox 调用,您不能这样做。 您需要实现自己的 MessageBox 才能执行此操作。

With the standard MessageBox call, you can't. You'd need to implement your own MessageBox in order to do this.

鹤仙姿 2024-07-13 23:43:04

我不相信标准消息框调用可以实现这一点。

您最好编写自己的包含此功能的消息框。

(或者,您可以编写一个单独的线程,持续监视屏幕,等待该消息框出现,禁用重试按钮,等待 10 秒,然后重新启用它。这不好玩。说真的,换一种方式吧。)

I don't believe this is possible with the standard message box call.

You would probably be better off writing your own message box that includes this functionality.

(Or, you could write a separate thread that continually watches the screen waiting for that message box to appear, disable the retry button, wait 10 seconds and reenable it. Not fun. Seriously, do it the other way.)

生生不灭 2024-07-13 23:43:04

从 Vista 开始,您可以使用任务对话框——一个比简单消息框更复杂的对话框。 更多信息和链接 这里

Since Vista you can use taskdialog -- a more sophisticated dialog than a simple message box. More info and links here.

话少心凉 2024-07-13 23:43:04

我同意 efotinis,这并非不可能,一旦你有了 HWND,你就可以用它做任何你想做的事情。 这只是一个“你真的需要这些技巧还是只创建自己的消息框对话框会更好”的问题吗?

另一种不太好的查找 HWND 的方法(这显然会让您访问消息框中的所有内容)是启动一个线程并使用 EnumChildWindows 循环轮询消息框句柄。 但我个人也更喜欢 WH_CBT 挂钩。

I agree with efotinis, it's not impossible, once you have the HWND you can do whatever you want with it. It is just a matter of "do you really need the hacks or are you better off with just creating your own message box dialog"?

Another not so nice way of finding the HWND (which would obviously give you access to eveything in the message box) would be to start a thread and ciclically poll for the message box handle by using EnumChildWindows. But I personally would prefer the WH_CBT hook also.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文