?
Solved

Detect Return keypress in a edit text widget

Posted on 1998-10-02
7
Medium Priority
?
319 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 30 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
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 

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

Technology Partners: 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!

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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