Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Keyboard input in Dialog box MFC

Posted on 1998-12-12
8
Medium Priority
?
1,181 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
  • 4
  • 4
8 Comments
 
LVL 4

Accepted Solution

by:
pagladasu earned 80 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

926 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