简体   繁体   English

防止X按钮关闭MFC对话框

[英]Prevent X Button Close MFC Dialog

I want to prevent my MFC dialog from being closed when window X button clicked, instead I want my windows to be hidden like ShowWindow(SW_HIDE); 我想防止在单击窗口X按钮时关闭MFC对话框,而是希望像ShowWindow(SW_HIDE)一样隐藏窗口。

I tried WM_ON_CLOSE, I get close message, I save my work, but can't prevent termination of my program and minimizing to tray. 我尝试了WM_ON_CLOSE,收到关闭消息,保存了我的工作,但是无法阻止程序终止并将其最小化到托盘上。

I want to prevent X button from closing my dialog, instead hiding it. 我想防止X按钮关闭对话框,而是将其隐藏。

Thanks in advance 提前致谢

Try adding a WM_SYSCOMMAND handler and trap the SC_CLOSE command. 尝试添加WM_SYSCOMMAND处理程序并捕获SC_CLOSE命令。

But before you do that, please rethink whether you want to do this. 但是在执行此操作之前,请重新考虑是否要执行此操作。 The close button is one of the most fundamental controls in Windows, and overriding its behavior can only be confusing. 关闭按钮是Windows中最基本的控件之一,重写其行为只会造成混乱。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM