本文简单介绍一下基于对话框的MFC应用程序的按键捕获和处理。
如下所示,捕获escape按键操作,然后直接返回不处理(正常情况下,该按键会导致OnClose()处理。
BOOL CSugDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->wParam == VK_ESCAPE)
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
关于消息捕获的更详细的处理,可以参考: http://www.codeproject.com/KB/dialog/pretransdialog01.aspx