Solved

How Do I use the WM_CHAR , WM_KEYDOWN , WM_KEYUP

Posted on 2001-07-26
8
1,917 Views
Last Modified: 2013-11-20
HOW DO I IMPLEMENT THE WM_CHAR ,WM_KEYDOWN, WM_KEYUP MESSAGES IN MY DIALOG BOX Application

 I tried this out but it did not work why???


Void CASCIIDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default

         MessageBox("hai");
         
     CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}


The message hai was not printed,when i pressed a key.


 if i want to detect a keypress what should i do

 i tried this but it did not work


void CASCIIDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
      if(nChar == VK_A)
       MessageBox("hai");
         
     CDialog::OnKeyDown(nChar, nRepCnt, nFlags);
}

    by using the code above i am trying to print the  
    message "hai" when the A key is pressed down but it
    not respond me.

    explain me how do i make use of VIRTUAL KEYS.


    give me a small example coding which clearly explaines
    how to implement these windowsmessages.

   I am working in dialog based application.



   
0
Comment
Question by:vsulu
[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
8 Comments
 
LVL 12

Accepted Solution

by:
migel earned 25 total points
ID: 6325749
Hi!
you need to use PreTranslateMessage for that messages
0
 
LVL 31

Assisted Solution

by:Zoppo
Zoppo earned 25 total points
ID: 6325803
>I tried this out but it did not work why???
Because default implementation of CDialog::PreTranslateMessage() calls CWnd::PreTranslateInput() which itself calls CWnd::IsDialogMessage() for key- and mouse-messages. This IsDialogMessage() then dispatches the message so it nevermore reaches your dialog class.

You'll need to override PreTranslateMessage for your dialog class as migel suggested.

ZOPPO


PS: This is only additional info ... give the points to migel.
0
 
LVL 12

Expert Comment

by:migel
ID: 6325839
>>to ZOPPO
your suggestion is more explanative (...hmm sorry my English is not so good).
0
Independent Software Vendors: 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 31

Expert Comment

by:Zoppo
ID: 6325857
to migel:
I believe it's a good habit to not only tell the people 'do this' but to tell them 'do this in that way because ...', because I think so people can faster learn mechanisms used in MFC.

Further I don't think my English is better, but I guess my German is as good as your Russian     ;o)

ZOPPO
0
 
LVL 12

Expert Comment

by:migel
ID: 6326056
to zoppo
>>Completelly agree
0
 
LVL 1

Expert Comment

by:ksenthilraj
ID: 6831036
Listening
0
 
LVL 12

Expert Comment

by:migel
ID: 6831176
Hey!
anybody here??
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490570
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : Zoppo, migel (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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