Solved

Redirecting Keyboard Input

Posted on 2003-11-07
3
274 Views
Last Modified: 2013-11-20
I have a dialog window that contains a CRichEdit control used for chat input.  There are a number of other controls in the window but none require input from the user.   Some of these 3rd party controls steal the focus from the edit.  I want all keys to go to the richedit.
0
Comment
Question by:vprex
3 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9699953
Override PreTranslateMessage function of Dialog
Good LUck
0
 

Accepted Solution

by:
jmfugate earned 250 total points
ID: 9704181
Specifically, you can override the PreTranslateMessage function in the derived CDialog class for your dialog box to handle the keyboard messages.

Then you can test the incoming messages for keyboard events, such as WM_KEYDOWN, WM_KEYUP, and WM_CHAR.  Then you can send those messages to the specific control you want (using PostMessage or SendMessage) and return TRUE to let the message loop know you handled the message.

For example, something like:

BOOL CYourDialog::PreTranslateMessage( MSG* pMsg)
{
  switch(pMsg->message)
  {
    case WM_KEYDOWN:
    case WM_KEYUP:
    case WM_CHAR:
      m_rcheditControl.SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam);
      return TRUE;
      break;  //for style;
     default:
      break;
  }
  //handle normally
  return CDialog::PreTranslateMessage(pMsg);
}
0
 

Author Comment

by:vprex
ID: 9744744
Neither of these comments is correct actually.  I had to call SetFocus prior to passing the message.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 42
Best tools for Backup and restore of Wordpress site 6 57
"Black Box" Testing of Control System Software 2 53
Problem to App 4 83
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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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