MFC中屏蔽ESC和回车关闭对话框

Posted on In Programming

解决方法是在CDialog::PreTranslateMessage() 的重载函数中将ESC和回车按键的消息处理掉.

直接上代码:

BOOL
CResultCollectorDlg::PreTranslateMessage(MSG* pMsg)
{
  if(pMsg->message == WM_KEYDOWN) {
    switch(pMsg->wParam) {
      case VK_RETURN: //回车
        return TRUE;
      case VK_ESCAPE: //ESC
        return TRUE;
    }
  }
  return CDialog::PreTranslateMessage(pMsg);
}

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *