Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple CEdit question

Posted on 1998-07-28
4
Medium Priority
?
407 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 40 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month7 days, 18 hours left to enroll

824 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