Solved

How to find the ascii values for SHIFT+ KEYS

Posted on 2001-07-26
3
486 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 74
Hibernate methods 2 71
either24  challenge 19 97
canBalance challenge 34 81
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: 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…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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