Solved

How to find the ascii values for SHIFT+ KEYS

Posted on 2001-07-26
3
480 Views
Last Modified: 2013-11-20
I want to find the acii value for the shift+keys.

 I have edit controls in my project and i want to allow the entry of
  numbers alone and "." for decimal point,so this my coding i have
  done in the pretranslatemessage().



BOOL CTrans::PreTranslateMessage(MSG* pMsg)
{
     // TODO: Add your specialized code here and/or call the base class
         
          char q[10];
           ::GetClassName(::GetFocus(),q,10);

     
      if(strcmp(q,"Edit")==0)
      {

          CWnd* ww = GetFocus();

          switch(pMsg->message)
           {
 
             case WM_KEYDOWN:
                    {
               
                 CString str;
              ww->GetWindowText(str);
        if(pMsg->wParam==190  && str.Find(".",0) ==-1)
           return  CDialog::PreTranslateMessage(pMsg);
          if(pMsg->wParam ==9 ||pMsg->wParam ==27||pMsg-
           >wParam >= 36 && pMsg->wParam <= 39 || pMsg-
           >wParam==8) return CDialog::PreTranslateMessage
           (pMsg);
                 
     if(!isdigit(pMsg->wParam))
     if(!(pMsg->wParam==46|| pMsg->wParam==8))
      return true;
     )
                 
          }
     }
     
     return CDialog::PreTranslateMessage(pMsg);
}



for the key 1 to 0 and for the . key when i use the shift keys !,@,#,$,%,^,&,*,(,),> are entered in the edit control I don't want the shift+key operation to work.

   help me regarding this.
0
Comment
Question by:vsulu
3 Comments
 
LVL 12

Accepted Solution

by:
migel earned 25 total points
ID: 6321320
Hi!
you can just detect than shift key pressedand bypass this key press:
if (::GetKeyState(VK_SHIFT) < 0) // key pressed
 return TRUE;
0
 
LVL 3

Assisted Solution

by:aphillips
aphillips earned 25 total points
ID: 6321956
You can avoid the problem using WM_CHAR, but here are some general ways to enhance your code:

1. Don't call GetFocus within PreTranslateMessage.  The current message is not nec. for the window with focus.

2. You allow processing of HOME (36) but not END (35).  You seem to be handling backspace in 2 places.  In fact the if statements could a bit more logically organised.

3. Use the VK_* values instead of numbers to make your code easier to read.  A few comments explaining what is being done would help too.

4. You can handle the WM_KEYDOWN message in the OnKeyDown handler rather than in PreTranslateMessage.  This is more obvious and efficient.  Your PreTranslateMessage is called for every message received by the window which could slow down mouse processing, eg. if mouse move events are being used.

5. If you handle the WM_CHAR message (in OnChar) then you don't have to worry about the SHIFT key (or tab, Escape etc) at all.  Windows does it for you.

I hope this helps.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9490558
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : migel, aphillips (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

867 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

22 Experts available now in Live!

Get 1:1 Help Now