Solved

Redirecting Keyboard Input

Posted on 2003-11-07
3
275 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
Host to IP 7 80
Expand macro to ask for filename column 8 37
Making an alias 7 101
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…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

861 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