[英]How to disable that an MFC application exits on pressing ESC or ALTF+F4?
I have an MFC application, which i don't want to be closed during the running. 我有一个MFC应用程序,我不想在运行期间关闭它。 I have disabled the "X" icon in the right upper corner, but now if i press the ESC key, or ALT+F4 it still closes. 我已禁用右上角的“X”图标,但现在如果我按下ESC键,或ALT + F4它仍然关闭。
How can i disable this, so it won't close, if someone press those keys? 我怎么能禁用它,所以如果有人按这些键它不会关闭? After the program has finished running i want to reenable them. 程序运行完毕后,我想重新启用它们。
Thanks, 谢谢,
kampi kampi
If you handle the WM_CLOSE
message and throw it away. 如果您处理WM_CLOSE
消息并将其丢弃。 (ie Don't call DefWindowProc
), then the window won't close. (即不要调用DefWindowProc
),那么窗口就不会关闭。
You could also register the window class with the CS_NOCLOSE
style, to disable all of the normal ways of closing the window. 您还可以使用CS_NOCLOSE
样式注册窗口类,以禁用关闭窗口的所有常规方法。
Can't say for Esc key, but as far as Alt+F4 goes, it sends Close command to the main window. 不能说Esc键,但就Alt + F4而言,它会向主窗口发送Close命令。 You basically need to override OnClose event and keep it empty (not call base method). 您基本上需要覆盖OnClose事件并将其保持为空(不是调用基本方法)。 That should do the trick. 这应该够了吧。
PS Since I haven't touched MFC in many years, it may not be 100% true. PS因为我多年没有接触过MFC,所以可能不是100%真实。 Just how I remember it. 我是多么记得它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.