Solved

Dialog always needs to see keypresses...

Posted on 1998-06-23
5
261 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
  • 4
5 Comments
 
LVL 2

Accepted Solution

by:
Belgarat earned 60 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

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: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

838 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