Solved

Keyboard input in Dialog box MFC

Posted on 1998-12-12
8
1,121 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 54
how do i create updater to My Activex application? 3 94
Expand macro to ask for filename column 8 37
haveThree challenge 22 121
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…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

840 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