Tuesday, July 26, 2011

Dialog Getting Closed of Pressing Escape Button MFC

Add this declaration in .h file
BOOL PreTranslateMessage(MSG*);

and this in .cpp file
BOOL ClassName::PreTranslateMessage(MSG* pMsg)
{
     if(pMsg->message==WM_KEYDOWN)
     {
       if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
       {
          pMsg->wParam=NULL ;
       }
      }
     return CDialog::PreTranslateMessage(pMsg);
}

should repeat this in all dialogs..