Solved

Detect Return keypress in a edit text widget

Posted on 1998-10-02
7
315 Views
Last Modified: 2013-11-20
How can I get noticed when user press the "Enter" key in a edit text widget after user enter their value.
0
Comment
Question by:nicolet
  • 4
  • 2
7 Comments
 

Author Comment

by:nicolet
ID: 1322880
Edited text of question
0
 

Expert Comment

by:umarama
ID: 1322881
Widget means what ?
0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 10 total points
ID: 1322882
The easiest way to get thje same effect is to add an OK button to the dialog.

The short-cut key for OK is return

Add a handler OnOK in the dialog.

Please note you can hide the OK button if you don't really want one visible using
GetDlgItem(IDOK)->ShowWindow(SW_HIDE) ;

Also base class of OnOK (so if you call this) closes the dialog.

If you really want the edit control to handle the return key itself, (1) derive class from CEdit using class wizard (say CMyEdit), (2) add a member variable of this type to the dialog, and (3) in this class process WM_KEYDOWN, WM_KEYUP, etc.

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Author Comment

by:nicolet
ID: 1322883
Thank You!

0
 

Author Comment

by:nicolet
ID: 1322884
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!
0
 

Expert Comment

by:umarama
ID: 1322885
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
0
 

Author Comment

by:nicolet
ID: 1322886
Thank You!
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expand macro to include alternate header placement and naming 5 71
List out all word 7 293
bigDiff challenge 17 106
Thin secure Windows 10 5 98
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question