Solved

How to find the ascii values for SHIFT+ KEYS

Posted on 2001-07-26
3
474 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

15 Experts available now in Live!

Get 1:1 Help Now