0

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?

Himanshu
  • 4,327
  • 16
  • 31
  • 39

1 Answers1

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);
}
Himanshu
  • 4,327
  • 16
  • 31
  • 39
Chandra
  • 471
  • 2
  • 10
  • 1
    Copying 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