Solved

Detect Return keypress in a edit text widget

Posted on 1998-10-02
7
313 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 73
sumDigits challenge 9 98
sumHeights  challenge 17 61
Updating statistics with error notification email in SQL server 4 45
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

759 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now