Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:escmodaldialog [2015/09/14]
developer:sdksamples:escmodaldialog [2020/08/14] (current)
Line 1: Line 1:
 +====== Handling Enter and Escape from Modal Dialogs ======
 +====== C++ ======
 +> **Version:** //Rhino 4.0//
 +> **Summary:** //Preventing modal dialogs from closing when the Enter or Escape key is pressed.//
 +
 +=====Question=====
 +How do I stop my MFC modal dialog box from closing when the user presses the Enter or Escape keys?
 +
 +=====Answer=====
 +The first step is to, on your CDialog-drived class, override the CWnd::PreTranslateMessage virtual function. This function is used translate window messages before they are dispatched to the TranslateMessage and DispatchMessage Windows functions. Then, add the following block of code:
 +
 +
 +<code c++>
 +BOOL CMyModalDialog::PreTranslateMessage( MSG* pMsg )
 +{
 +  if( pMsg )
 +  {
 +    if( pMsg->message == WM_KEYDOWN )
 +    {
 +      if( pMsg->wParam == VK_RETURN | pMsg->wParam == VK_ESCAPE )
 +        pMsg->wParam = NULL;
 +    } 
 +  }
 +  // Call the base class PreTranslateMessage. In this example,
 +  // CRhinoDialog is the base class to CMyModalDialog.
 +  return CRhinoDialog::PreTranslateMessage( pMsg );
 +}
 +
 +</code>
 +
 +
 +{{tag>Developer cplusplus}}
  
developer/sdksamples/escmodaldialog.txt ยท Last modified: 2020/08/14 (external edit)