在很多时候,我们都需要屏蔽键盘的Esc键,以此来减少用户的误操作。在Class View 列表右键需要屏蔽的类的类名,选择properties,安然选择Overrides里的PreTranslateMessage,添加此函数,接着对其进行处理。
BOOL CLoginDialog::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if (WM_KEYDOWN == pMsg->message)
{
int iKey = (int)pMsg->wParam;
// 屏蔽键盘esc
if ((VK_ESCAPE == iKey) || (VK_RETURN == iKey))
{
return TRUE;
}
}
return CDialog::PreTranslateMessage(pMsg);
}