Link to home
Start Free TrialLog in
Avatar of nicolet
nicolet

asked on

Detect Return keypress in a edit text widget

How can I get noticed when user press the "Enter" key in a edit text widget after user enter their value.
Avatar of nicolet
nicolet

ASKER

Edited text of question
Widget means what ?
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nicolet

ASKER

Thank You!

Avatar of nicolet

ASKER

This Edit box is in a child window dialog, It does not response to "OnOK". Would you please be more detailed about using derived class from CEdit and process WM_KEYDOWN, WM_KEYUP. to catch a "Return" key press.

Thank You!
Try this out ...

In your derived CEdit class, say CMyEdit, add an handler for PreTranslateMessage ...

BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
{
  if ((pMsg->message == WM_KEYDOWN) && 
      (pMsg->wParam == VK_RETURN))
       .... CALL YOUR FUNCTION (Enter has been detected)
       return TRUE;// Saying that you have handled the msg
  }
  return CEdit::PreTranslateMessage(pMsg);
}

You can also translate your key strokes to some other key stroke.
For Ex: If Enter needs to be treated as Tabs, you can do the following ..

BOOL CMyEdit::PreTranslateMessage(MSG* pMsg)
{
  if ((pMsg->message == WM_KEYDOWN) && 
      (pMsg->wParam == VK_RETURN))
       pMsg->wParam = VK_TAB;// Cheating !!
  }
  return CEdit::PreTranslateMessage(pMsg);
}

Hope this helps
Avatar of nicolet

ASKER

Thank You!