How to identify Enter Key pressed by user ?
-
Hi All, In my project I want to check Whether user press Enter key or not after type a text in text box. In which event I have to check it and how can i check it. Thanks in Advance Atul
-
Hi All, In my project I want to check Whether user press Enter key or not after type a text in text box. In which event I have to check it and how can i check it. Thanks in Advance Atul
What type is the project?
Maxwell Chen
-
Hi All, In my project I want to check Whether user press Enter key or not after type a text in text box. In which event I have to check it and how can i check it. Thanks in Advance Atul
This should help: http://www.codeproject.com/dialog/pretransdialog01.asp[^]
cheers! mykel
OMM: "Let us be thankful we have an occupation to fill. Work hard, increase production, prevent accidents and be happy."
-
Hi All, In my project I want to check Whether user press Enter key or not after type a text in text box. In which event I have to check it and how can i check it. Thanks in Advance Atul
Did you use of
PreTranslateMessage
. -
Hi All, In my project I want to check Whether user press Enter key or not after type a text in text box. In which event I have to check it and how can i check it. Thanks in Advance Atul
The use of
PreTranslateMessage()
*might* work, but most implementations are incorrect. The other downside is that it permanently ties the child control to the parent. A better solution is to derive a class fromCEdit
. Override theOnGetDlgCode()
method and returnDLGC_WANTALLKEYS
. Then override theOnChar()
method like:void CMyEdit::OnChar( UINT nChar, UINT nRepCnt, UINT nFlags )
{
switch (nChar)
{
case VK_RETURN:
GetParent()->SendMessage(some_custom_msg, GetDlgCtrlID(), (LPARAM) this);
return;
}CEdit::OnChar( nChar, nRepCnt, nFlags );
}
When the edit control "sees" the Enter key, it posts a message to the parent indicating such. The parent can then respond accordingly, if at all.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne