Solved

Keyboard input in Dialog box MFC

Posted on 1998-12-12
8
1,100 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

11 Experts available now in Live!

Get 1:1 Help Now