窗口的MessageBox无视WM_CLOSE [英] Windows MessageBox ignoring WM_CLOSE

查看:376
本文介绍了窗口的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( ),并用 WM_QUIT 消息传递给应用程序的主窗口 PostMessage的()

The modal dialog'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 dialog ... - but at least on my current win7 machine this isn't the case.

此外,它是主窗口接收的情况下的 WM_SYSCOMMAND 的wParam 设置为 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 dialog box's styles...? I did not investigated this further.).

不过,添加下面的分支到窗口的消息循环的开关应该做的结束条件下的应用工作的描述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(...);

  ...

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

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