Solved

Detect Return keypress in a edit text widget

Posted on 1998-10-02
7
314 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell script to login to remote m/c and execute commands 10 78
Unix Command -- Challenging  question 7 86
wordappend challenge 8 143
Excel file not created as expected 7 46
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

10 Experts available now in Live!

Get 1:1 Help Now