Solved

Keyboard input in Dialog box MFC

Posted on 1998-12-12
8
1,108 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 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Define unique primary key 9 89
conditional code and condition difference 9 75
tripleUp challenge 7 73
zeroMAx challenge 20 86
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

947 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

23 Experts available now in Live!

Get 1:1 Help Now