MFC中回车处理
作者:互联网
先重写PreTranslateMessage函数,使得能处理WM_KEYDOWN消息:
BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam);
return 0;
//return CDialog::PreTranslateMessage(pMsg);
}
然后添加WM_KEYDOWN消息的消息响应函数,用if来判断是否按下回车键:
void CMyDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
// 按下回车键, 窗口会关闭
if (nChar == VK_RETURN)
{
EndDialog(0);
}
CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}
完成。
标签:PreTranslateMessage,nRepCnt,处理,WM,pMsg,MFC,UINT,回车,nChar 来源: https://blog.csdn.net/laciqs/article/details/114154212