Solved

Keyboard input in Dialog box MFC

Posted on 1998-12-12
8
1,127 Views
Last Modified: 2013-11-20
I don't ask too many questions, but this has been a problem for a while, and as you know M****S*** has inefficient information.

So please be as simple as possible when answering this, i am not looking for terribly comlex, pointers going crazy thing. Just a simple answer.


HERE GOES:

I have a MFC dialog box.

I have a listbox.
member name m_list1;

I have a list of stuff in a multiselect.

I want to delete a selected bunch of things at a touch of delete.

I have tried using the VK_DELETE.

I have inserted a OnKeyDown(3 param)
which I added by the wizard.  AND IT DOESN'T go there when a key on the keyboard is pressed. I have put a message box there just to see if it even gets there but it doesn't.

Can anybody suggest a way to solve this problem.  with key detect working and with the simplest method thinkable?

Thanks in advance.
0
Comment
Question by:The_Brain
[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
  • 4
8 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 20 total points
ID: 1326115
Don't try to trap OnKeyDown(). It will only work if there are no controls. Instead try trapping the PreTranslateMessage - something like this:

BOOL CMyDialog::PreTranslateMessage(MSG* pMsg)
{
      // TODO: Add your specialized code here and/or call the base class
      if(pMsg->message==WM_KEYUP){
            if(pMsg->wParam==VK_DELETE)
                  MessageBox("RUN");
      }
      return CDialog::PreTranslateMessage(pMsg);
}

Hope this helps
Thanks
pagladasu
0
 
LVL 1

Author Comment

by:The_Brain
ID: 1326116
Could you elaborate on WHAT pretranslate message does, and why if it works will it it work?
0
 
LVL 1

Author Comment

by:The_Brain
ID: 1326117
Could you elaborate on WHAT pretranslate message does, and why if it works will it it work?
0
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!

 
LVL 1

Author Comment

by:The_Brain
ID: 1326118
How am I suppose to put it in? by wizard. Or by hand? if by hand, how?
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1326119
You put it using ClassWizard.
Actually before every windows message is dispatched to the functions TranslateMessage and DispatchMessage, they can be filtered thru PreTranslateMessage.

pagladasu
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1326120
You put it using ClassWizard.
Actually before every windows message is dispatched to the functions TranslateMessage and DispatchMessage, they can be filtered thru PreTranslateMessage.

pagladasu
0
 
LVL 1

Author Comment

by:The_Brain
ID: 1326121
Thanks that works fine...
To bad there is no A+, other wise I would have given you that instead.  Well done, that is exactly what I wanted.  Where did you get //TODO ?  I just created my own.  Oh well, it works no need to worry.  Is this a good idea
for games at all?  just a comment needed. thanks.

Don't want to be picky but this also works under PreTranslateMessage(MSG* pMsg)

if (GetAsyncKeyState(VK_DELETE))
  {
    MessageBox(0, "You have pushed delete!", 0);      
  }
return CDialog::PreTranslateMessage(pMsg);

?!.  is your way better, I know about the upkey, downkey status so I can use either depending on my needs right?
Thanks again... I've increased it to 20 for the answer.  It was exactly how I wanted it. :)
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1326122
Where did I get TODO - I didn't, classwizard added it.
I had no particular reason to use WM_KEYUP - it all depends on what you want to do.
I cannot immediately opine on the Games aspect unless you tell me what you really want it for in your game - yes it can be used for example to trap the escape key or some some other key the user may need, say for example to quit or pause.
Thanks for your feedback. Best of luck on your game.
In case you need more clarifications, do contact me at espical@hotmail.com
0

Featured Post

Industry Leaders: 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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

696 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