Windows MessageBox 忽略 WM_CLOSE [英] Windows MessageBox ignoring WM_CLOSE

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

问题描述

我们有一个遗留的 C Windows 应用程序,当发生致命连接错误时,它会通过 MessageBox 调用弹出一个模式窗口.我们的网络工程师可能会同时运行许多这样的应用程序.有时,网络故障会导致这些应用程序正在处理的连接同时失败.

We've got a legacy C Windows application which pops up a modal window via the MessageBox call when a fatal connection error occurs. Our network engineers may be running many of these applications at once. Occasionally, a network glitch will cause the connections being handled by these applications to fail simultaneously.

在 Windows 7 上,从任务栏中选择关闭所有窗口"功能确实有效,因为模式对话框似乎没有处理 WM_QUIT 消息.我通常在 Linux 系统上工作,但我的 MSDN 研究表明,我可以捕获和处理此消息的唯一方法是创建自己的对话框并自己处理消息.

On Windows 7, selecting the 'Close all windows' function from the taskbar does work, because the modal dialog does not appear to be processing the WM_QUIT message. I typically work on Linux systems but my MSDN research indicates that the only way I can catch and process this message is by creating my own dialog and handling the messages myself.

我担心我忽略了一个更简单的解决方案,谁能提供替代方案?

My worry is that I've overlooked an easier solution, can anyone offer alternatives?

推荐答案

模态对话的消息循环应该捕获 WM_QUIT 并在响应中调用 EndDialog() 并通过使用 PostMessage()WM_QUIT 消息发送到应用程序的主窗口.

The modal dialogue 's message loop should catch WM_QUIT and in response call EndDialog() and pass on the WM_QUIT message to the application's main window using PostMessage().

更新:

如果将 WM_QUIT 发送到模态对话框,上述方法将起作用......但至少在我目前的 win7 机器上不是这种情况.

The approach as proposed above would work, if a WM_QUIT would be sent to the modal dialogue ... - but at least on my current win7 machine this isn't the case.

此外,主窗口收到 WM_SYSCOMMANDwParam 设置为 SC_CLOSE 的情况是,默认消息处理程序会忽略它(这可能是由于模态对话框的样式......?我没有进一步调查.).

Moreover it is the case that the main window receives a WM_SYSCOMMAND with wParam set to SC_CLOSE and somehow the default message handler does ignore it (which might due to the modal dialogue box's styles...? I did not investigated this further.).

但是,将以下分支添加到 ma​​in 窗口的消息循环的 switch 应该可以完成在 OP 描述的条件下结束应用程序的工作:

However, adding the following branch to the main window's message loop's switch should do the work of ending the application under the conditions describe by the OP:

  ...

  case WM_SYSCOMMAND:
    if (SC_CLOSE == wParam)
    {
      PostQuitMessage(<whatever code shall be returned>);
    }

    return DefWindowProc(...);
   
  ...

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

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