[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Redirecting Keyboard Input

Posted on 2003-11-07
3
Medium Priority
?
281 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 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

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 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