简体   繁体   English

如何在按ESC或ALTF + F4时禁用MFC应用程序退出?

[英]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.

相关问题 如何禁用MFC应用程序的WinMain入口点? - How to disable WinMain entry point for a MFC application? 如何使用功能区将F10用作MFC应用程序中的快捷方式 - How to use F10 as a shortcut in an MFC application using a Ribbon 如何禁用MFC Feature Pack应用程序中的MenuBar项目中的文本恢复? - How to disable the restoration of text in MenuBar items in an MFC Feature Pack application? 如何禁用在Windows MFC应用程序中创建.pf(预取)文件的功能? - How to disable creating .pf (prefetch) file in Windows MFC application? VC++:如何防止esc关闭对话框(不是mfc) - VC++ : How to prevent esc from closing a dialog box (not mfc) 如何通过在Qt中按esc退出无限while循环? - How to get out of infinite while loop by pressing esc in Qt? 如何通过按Esc键使非模式QDialog不可取消? - How to make non-modal QDialog not cancellable by pressing Esc key? Unreal Engine 4 蓝图如何禁用 ESC 键? - Unreal Engine 4 blueprints how to disable ESC key? QT Embedded:如何向ESC(转义),F1和类似键生成事件 - QT Embedded: How to generate an event to ESC (Escape), F1 and such keys 如何禁用MFC SDI应用程序中的消息框“无法创建空文档”消息框 - how to disable message box “Fail to create Empty Document ” Message box in MFC SDI application
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM