?
Solved

Keyboard messages in a Modal Dlg

Posted on 1997-06-12
6
Medium Priority
?
326 Views
Last Modified: 2013-11-20
 I have a modal dialog box which in which I would like to do "something" when a key is pressed (i.e. F4, pageup, page down, +, -, 1, 2, 3).  I tried onkeydown and onchar, but those do not work.

  In addition, I would like to know if there is a way to disable or enable certain keys.  There are cases where I only want the user to be able to use the numeric keypad and not allow for any alpha characters.

  If you have any information, email me at aguevara@sprynet.com

Have a good day,
Angelo
0
Comment
Question by:aguevara020397
[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
  • 3
  • 3
6 Comments
 
LVL 4

Accepted Solution

by:
mbhakta earned 40 total points
ID: 1302070
The onkeydown and onchar didnot work because the message was not routing to your CDialog but going to another control on the dialog say a button or whatever belongs to tab index 1.  You will have to carefully work out the messaging for dialogs as it works a bit different from other windows. There is no problem in achieving what you are planning to do, but take care you don't get lost in the CDialog messaging maze.
0
 

Author Comment

by:aguevara020397
ID: 1302071
I still don't know how to do it though.  Can you tell me where I can find and example ??
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302072
Actually, I did no coding at all. What I just did is override the OnKeyDown and OnChar for the dialog. Then added some trace prints on these calls. Ran it , pressed some keys did not work. I realized the focus was on a button Ok and not on the dialog. Delete all controls on top of the dialog and boom I could see the messages passing thru and so the trace print. It is pretty simple try it. Also I just remembered one of MSJ's back issues had this article may be 1 year ago. Check their archives.
0
Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

 

Author Comment

by:aguevara020397
ID: 1302073
mbhakta,
  I download several issues of the MSJ source code from 1996 and could not find it.  I also saw that you had answered the same question before and you had stated to "Check the MSJ issues a couple of months ago (say from March 96). There was an article explaining how to do keystrokes for CDialogs ...."  I downloaded the march,may,june and july issues and could not find it.
  Would it possible for you to look at your back issues and find it for me ? I am not subscribed to MSJ so I can't very well do so.

  Have a good day,
Angelo
0
 
LVL 4

Expert Comment

by:mbhakta
ID: 1302074
I will see what I can do for you. Give me about 20 hours. Good night.
0
 

Author Comment

by:aguevara020397
ID: 1302075
Mbhakta,

   I found an example on how to trap keyboard messages while in a CDialog, the example essentially suggested to do the following

(1) Create a CDialog pointer in your main App class (CWinApp)
(2) Initialize it to NULL in the InitInstance
(3) Set to a valid value in the constructor of your CDialog class
(4) Set back to NULL on the onDestroy procedure of your CDIalog class
(5) Define virtual BOOL ProcessMessageFilter( int code, LPMSG lpMsg ); on the CWinApp header file
(6) Insert the ProcessMessageFilter( int code, LPMSG lpMsg ) in the CWin App CPP file
(7) In the ProcessMessageFilter function, check to see if the CDialog pointer is NON-NULL, if it is then we know a key has been pressed in the CDialog class,
you can do a if (lpMsg->message==WM_KEYDOWN) to determine if a key has been pressed.

I still can't figure out how to find out what key specifically has been pressed, I am looking into that since based on the key pressed (PageUp, PageDown, +, -,
keys) I would like to perform different functions.

If you have any ideas on how to decipher the key pressed, please let me know.
Angelo
aguevara@sprynet.com

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

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