Solved

Simple CEdit question

Posted on 1998-07-28
4
391 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

856 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