Solved

Keyboard messages in a Modal Dlg

Posted on 1997-06-12
6
322 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 20 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
Independent Software Vendors: 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!

 

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

Independent Software Vendors: 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

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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

695 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