Solved

How Do I use the WM_CHAR , WM_KEYDOWN , WM_KEYUP

Posted on 2001-07-26
8
1,901 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

821 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