?
Solved

Dialog always needs to see keypresses...

Posted on 1998-06-23
5
Medium Priority
?
264 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

765 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