Solved

Trap CEdit  keystrokes

Posted on 1998-09-27
4
560 Views
Last Modified: 2013-11-20
Hi Everyone!

I would like to trap the Enter keypress in a CEdit control and prosses it as a Tab key, in other words I would like to be able to move from CEdit to CEdit control using the Enter key.
Please help as I am unable to solve this one myself.

Regards Vardis
0
Comment
Question by:vardis
  • 2
4 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1322643
1. Derive a class from CEdit and override CEdit::OnChar().
2. When an Enter key is detected, post a user-defined message (e.g. WM_APP + 1) to the parent window of the edit control.
3. When the dialog box receives the user-defined message, call CDialog::NextDlgCtrl() to simulate a tab key.
0
 

Expert Comment

by:umarama
ID: 1322644
I have a simpler solution to your problem.

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))
      pMsg->wParam = VK_TAB;
      // Return gets translated to TAB - simulation
  }
  return CEdit::PreTranslateMessage(pMsg);
}

This works.
0
 

Accepted Solution

by:
umarama earned 50 total points
ID: 1322645
Try out my solution. Please refer to my previous comment
0
 

Author Comment

by:vardis
ID: 1322646
Thank you umarama for the solution.
You're right it is a simpler solution and it did work.

Thank you!

Vardis
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

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. …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

943 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

5 Experts available now in Live!

Get 1:1 Help Now