如何区分“关闭所有窗口”和“关闭”单个窗口在MFC与Windows 7? [英] How can I distinguish between "Close All Windows" and "Close" individual windows in MFC with Windows 7?

查看:236
本文介绍了如何区分“关闭所有窗口”和“关闭”单个窗口在MFC与Windows 7?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2005与MFC和Windows 7.我有一个应用程序与许多对话窗口。

I am using Visual Studio 2005 with MFC and Windows 7. I have an application with many dialog windows.

我使用OnSysCommand检查SC_CLOSE消息,并检查lParam确定是否从任务栏或对话框上的关闭按钮启动。但是如何确定关闭消息是从任务栏关闭所有窗口还是只关闭任务栏中的单个对话框?

I use OnSysCommand to check for SC_CLOSE messages and check the lParam to determine if this is initiated from the task bar or the close button on the dialog. But how can I determine whether a close message is a "close all windows" from the task bar or just closing an individual dialog from the task bar?

感谢

推荐答案

我不认为你会得到一个单一的消息解决。

I don't think that you get this solved with a single message.

当您关闭应用程序时,您还必须区分鼠标操作和Alt + F4
如果使用Alt + F4关闭应用程序,消息看起来是相同的,如从任务栏关闭它(查看lParam值)

When you Close the application you have to distinguish also between a mouse action and Alt+F4 If you close the application with Alt+F4 the message looks identical like closing it from the task bar (Look at the lParam value)

您可以查看使用GetMessage检索的最后一条消息(最后一条输入消息)。如果消息来自任务栏,它是一个发布的WM_SYSCOMMAND。如果消息来自内部,您会收到WM_SYSCOMMAND作为SendMessage。

You can look at the last message that was retrieved with GetMessage (the last input message). If the message comes from the task bar it is a posted WM_SYSCOMMAND. If the message comes from the inside you receive the WM_SYSCOMMAND as SendMessage.

您可以使用AfxGetCurrentMessage确定最后一个输入消息是什么。如果你在这里找到WM_SYSCOMMAND,关闭来自任务栏。

You can use AfxGetCurrentMessage to determine what was the last input message. If you find WM_SYSCOMMAND here the close comes from the taskbar. If you find a keyboard or mouse message here the message comes form the user input.

提示:使用Spy ++检查此行为。

Tip: Use Spy++ to examine this behavior.

这篇关于如何区分“关闭所有窗口”和“关闭”单个窗口在MFC与Windows 7?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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