I have a dialog based MFC application which I want to close/terminate only using the X(close) button given in title bar and disabling other shortcuts to do so.
for example: pressing the Esc key. Can someone help?
Asked
Active
Viewed 316 times
0

Himanshu
- 4,327
- 16
- 31
- 39

Prachi Geda
- 21
- 7
-
1http://stackoverflow.com/questions/17828258/how-to-prevent-mfc-dialog-closing-on-enter-and-escape-keys – Santosh Dhanawade Nov 24 '16 at 10:16
1 Answers
0
Override the PreTranslateMessage function and catch the use of VK_ESCAPE for capturing Esc key. Similar way you can catch other messages and bypass closing of dialog
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if ((pMsg->wParam == VK_RETURN) || (pMsg->wParam == VK_ESCAPE))
return TRUE;
}
return CDialog::PreTranslateMessage(pMsg);
}
-
1Copying a [poor answer](http://stackoverflow.com/a/17829314/1889329), without attribution, is called *"plagiarism"*. -1 for not even considering the proper MFC way of doing this. – IInspectable Nov 24 '16 at 18:29
-
Please let me know what I am doing here non MFC way, As I have used this in my previous project and copied the same. Let me know what is non MFC way, so that I can make that proper in my project too. Very thanks for your coming answer. – Chandra Nov 25 '16 at 04:32