Solved

How Do I use the WM_CHAR , WM_KEYDOWN , WM_KEYUP

Posted on 2001-07-26
8
1,886 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
8 Comments
 
LVL 12

Accepted Solution

by:
migel earned 25 total points
Comment Utility
Hi!
you need to use PreTranslateMessage for that messages
0
 
LVL 30

Assisted Solution

by:Zoppo
Zoppo earned 25 total points
Comment Utility
>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
Comment Utility
>>to ZOPPO
your suggestion is more explanative (...hmm sorry my English is not so good).
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 12

Expert Comment

by:migel
Comment Utility
to zoppo
>>Completelly agree
0
 
LVL 1

Expert Comment

by:ksenthilraj
Comment Utility
Listening
0
 
LVL 12

Expert Comment

by:migel
Comment Utility
Hey!
anybody here??
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

728 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

10 Experts available now in Live!

Get 1:1 Help Now