Solved

Simple CEdit question

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
xyBalance chalenge 58 93
Turn a spreadsheet into a vba executable. 2 87
child constructor and parent constructor, overriding and overloading 6 84
Work with App store 7 52
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 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