Solved

Simple CEdit question

Posted on 1998-07-28
4
392 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
[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
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
Define unique primary key 9 95
fizzArray  challenge 1 109
pre4 challenge 19 111
Updating statistics with error notification email in SQL server 4 120
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…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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