?
Solved

Dialog always needs to see keypresses...

Posted on 1998-06-23
5
Medium Priority
?
265 Views
Last Modified: 2013-11-20
I have a dialog box containing a long scrollable RichEdit that contains the text of an agreement.  There are two buttons, Yes I Do, & No I Don't Accept the agreement.  The default button when the dialog comes up is NO.  Even though it is not standard windows interface design, I need the dialog to react to PageUp, PageDown, ArrowUp, ArrowDown, no matter which button (or box) is currently highlighted.
I've used Class Wizard to generate functions for  WM_ONCHAR & WM_ONKEYDOWN, but they never get called (yes, me newbie).  I know how to talk to the box to scroll the text but I can't trap the keys.  
0
Comment
Question by:Musashi
[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
  • 4
5 Comments
 
LVL 2

Accepted Solution

by:
Belgarat earned 120 total points
ID: 1318335
The keys are send directly to the focused control, not to the dialog window, so if you're trying to trap some keys there, your handlers will not get called.
The first approach is to subclass the RichText control (create a derived class from CRichText) and add appropriate handlers. Then you add a member variable bound to the richedit control and manually change its type to CYourRichText in the dialog's header.
Probably more efficient is to override your dialog's member function
BOOL PreTranslateMessage(MSG *pMsg)
You can watch for WM_KEYDOWN there and do whatever you wish. This will capture ALL keypresses regardless of what control is currently focused. If your function returns 1, the message will be discarded. If you return 0, the message will be dispatched by the standard procedures (see help on CWnd::PreTranslateMessage).

0
 
LVL 1

Author Comment

by:Musashi
ID: 1318336
I found Article ID: Q117563 which directly addresses this question.  The title is "How to Trap WM_KEYDOWN Messages in a CDialog", and basically suggests to override the predefined overridable MFC hook function ProcessMessageFilter() to capture the messages before they get to the dialog box.

However, I won't be able to test this method vice the proposed answer until next week.  I'm new to the Expert's Exchange and would like some advice on how to handle the points&etc. if this method works for me. IE, Do I give you the points for giving me an answer or do I give myself the points somehow if I use my own answer.  Please understand I'm not trying to be stingy, just want to know the correct procedure.
0
 
LVL 1

Author Comment

by:Musashi
ID: 1318337
Tested decreasing the points, will return to 65 no matter what.
0
 
LVL 1

Author Comment

by:Musashi
ID: 1318338
That's odd, they rejected the decrease but not the comment.  I think I would have preferred an error message not a post.
0
 
LVL 1

Author Comment

by:Musashi
ID: 1318339
That's odd, they rejected the decrease but not the comment.  I think I would have preferred an error message not a post.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

650 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