Solved

Detect Return keypress in a edit text widget

Posted on 1998-10-02
7
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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