Solved

Simple CEdit question

Posted on 1998-07-28
4
383 Views
Last Modified: 2013-11-20
What is the proper way to test whether a user has press
a "decimal point" key in a CEdit class?

 nChar == VK_DECIMAL  is wrong ?



void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
  // TODO: Add your message handler code here and/or call default
  if (      nChar == '.' ||   // this is ok
        nChar == VK_DECIMAL )  // wrong ????
     {
         ....
     }
}
0
Comment
Question by:nancytan
  • 2
  • 2
4 Comments
 

Author Comment

by:nancytan
ID: 1319876
Edited text of question
0
 
LVL 2

Accepted Solution

by:
warmcat earned 20 total points
ID: 1319877
Hi Nancy -

WM_KEYUP and WM_KEYDOWN use the VK_* type keycodes, not WM_CHAR.  WM_CHAR is only issued - and OnChar() is called - only when ::TranslateMessage() successfully translates one of these VK_* constants into a normal character.

Because of this, the == '.' method is the correct one.  But if you had overriden WM_KEYDOWN (CMyEdit::OnKeydown), then the ==VK_DECIMAL method would be right.

Regards,

-Andy
0
 

Author Comment

by:nancytan
ID: 1319878
How about the backspace key?

I use nChar == VK_BACK in OnChar() and it seems to be correct.


oid CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
    {
      // TODO: Add your message handler code here and/or call default
      if ( nChar == VK_BACK ||   // why this is ok ?
            nChar == VK_DECIMAL )  // OK, this is wrong here
         {
             ....
         }
    }

0
 
LVL 2

Expert Comment

by:warmcat
ID: 1319879
Hi Nancy -

Yes... because VK_BACK has no corresponding ''normal character'' form (the old ^H notwithstanding) and yet is a keypress ::TranslateMessage() passes it through unchanged, whereas VK_DECIMAL does have a direct and full ''normal character'' equivalent: '.' and is passed on to OnChar() by ::TranslateMessage() as '.'.

If you had gone in at OnKeydown(), you would have had to use VK_DECIMAL as the translation to '.' would not have occurred yet.  In the VK_BACK case there is no translation to be performed and in both OnKeydown() and OnChar() it is VK_BACK.

-Andy
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

18 Experts available now in Live!

Get 1:1 Help Now