Solved

Dialog always needs to see keypresses...

Posted on 1998-06-23
5
258 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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 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 tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

759 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

22 Experts available now in Live!

Get 1:1 Help Now