How can I handle the Return key in a CEdit control?
问题 How can I handle the Return key ( VK_RETURN ) in a CEdit control? The CEdit control is parented to a CDialog . 回答1: You could also filter for the key in your dialog's PreTranslateMessage. If you get WM_KEYDOWN for VK_RETURN , call GetFocus . If focus is on your edit control, call your handling for return pressed in the edit control. Note the order of clauses in the if relies on short-circuiting to be efficient. BOOL CMyDialog::PreTranslateMessage(MSG* pMsg) { if (pMsg->message == WM_KEYDOWN &