Solved

How to find the ascii values for SHIFT+ KEYS

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
VB.NET how to use the Vertical ScrollBar 5 114
wordappend challenge 8 201
Detect file exist or not 3 180
Work with App store 7 68
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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 …
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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