?
Solved

Redirecting Keyboard Input

Posted on 2003-11-07
3
Medium Priority
?
279 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
[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
3 Comments
 
LVL 23

Expert Comment

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

Accepted Solution

by:
jmfugate earned 750 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

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. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

764 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