Solved

Redirecting Keyboard Input

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 98
how do i create updater to My Activex application? 3 74
sameEnds challenge 3 106
matchUp  challenge 6 48
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

706 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

19 Experts available now in Live!

Get 1:1 Help Now