禁用MFC应用程序的esc键退出 [英] Disable esc key exit for MFC Application
问题描述
您好,专家,我在MFC中有一个使用单个对话框窗口的应用程序.
我面临的问题是,当我按退出键时,它就会退出.
i希望当我按下自己制作的退出"按钮并同时按下窗口右上角的"x"(对话框中提供的默认关闭按钮)按钮但不按下"esc"键时退出它.
<我尝试清空"OnCancel"功能的实现.它解决了"esc"键的问题,但是当我按下"x"按钮时,它也禁用了退出功能.
请帮助我,当我不小心按下exit并关闭窗口时,这非常烦人.
如果可能,请告诉我添加方式,最小化按钮以及顶部的"x"(关闭)按钮.
请注意,
Swinder....
Hi experts,
I have an Application in MFC using single dialog window.
Problem i am facing is, it exits when i press escape key.
i want it to exit when i press "Exit" button that i made my self and also by pressing "x"(default close button provided in dialog) button on top right corner of window but not by "esc" key.
I tried emptying the implementation of "OnCancel" function. It solves the problem of "esc" key, but it also disables, exit when i press "x" button.
Please help me, it is very annoying when i accidentally press exit and window goes away.
If possible, tell me way to add, minimize button along with "x"(close) button on the top.
Regards,
Swinder....
推荐答案
请参见此处.
See here.
还可以使用PreTranslateMessage来拦截ESC键.使用类向导将函数添加到对话框,然后检查ESC键.
BOOL CDxf2NastranDlg::PreTranslateMessage(MSG* pMsg) <br />{<br /> // TODO: Add your specialized code here and/or call the base class<br /> // ESC key<br /> if(pMsg->wParam == VK_ESCAPE) { return TRUE; }<br /><br /> return CDialog::PreTranslateMessage(pMsg);<br />}<br />
Also, one use use PreTranslateMessage to intercept the ESC key. Add the function to the dialog using the class wizard, then check for the ESC key.BOOL CDxf2NastranDlg::PreTranslateMessage(MSG* pMsg) <br />{<br /> // TODO: Add your specialized code here and/or call the base class<br /> // ESC key<br /> if(pMsg->wParam == VK_ESCAPE) { return TRUE; }<br /><br /> return CDialog::PreTranslateMessage(pMsg);<br />}<br />
U可以在对话框顶部添加最小/最大化按钮对话框属性中的对话框.
U can add minimize/maximize button on top of the dialog box from the property of the dialog box.
这篇关于禁用MFC应用程序的esc键退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!