How to handle return key (VK_RETURN) in a CEdit control? CEdit is lying in a CDialog.
A:
Make certain the Edit Control style ES_WANTRETURN is set in the dialog resource for the control
SAMills
2009-02-12 14:58:07
This does not work. This is not what I want. I want to get RETURN key AND do something. Not just allow entering RETURN key.
knaser
2009-02-12 15:18:16
Then you'll need to subclass the edit control and handle the WM_CHAR or KeyDown messages which are answered in other SO questions. OR within the dialog's MessageMap, handle Edit Change messages from the control (sent for every character).
SAMills
2009-02-12 15:44:17
+2
A:
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 &&
pMsg->wParam == VK_RETURN &&
GetFocus() == m_EditControl)
{
// handle return pressed in edit control
}
}
Aidan Ryan
2009-02-12 21:08:55
A:
Try overloading this method in your edit control class:
http://msdn.microsoft.com/en-us/library/3zzfkd75%28VS.80%29.aspx
anand.arumug
2010-06-18 15:53:03