如何处理控件中的Returnkey(VK_RETURN
)CEdit
?该CEdit
控制父到CDialog
.
您还可以在对话框的PreTranslateMessage中过滤键.如果你得到WM_KEYDOWN
了VK_RETURN
,打电话GetFocus
.如果焦点在编辑控件上,请在编辑控件中调用您按下的返回处理.
注意if依赖于短路的子句的顺序是有效的.
BOOL CMyDialog::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN && GetFocus() == m_EditControl) { // handle return pressed in edit control return TRUE; // this doesn't need processing anymore } return FALSE; // all other cases still need default processing }