Detecting CR in an Edit Box

I have an edit box that gets a decimal value from the user.  I pick up the value with an UpdateData() in the routine for a pressed button in the same dialog box, and this works fine.  But if the user enters carriage-return after entering the  decimal input, the entire dialog box closes down and control exits my program. I thought I might be able to fix this by putting code in the EN_CHANGE routine for the edit box to look for CR, but this routine only gets called when a non-CR character is entered. CR does the same thing as before - closes down the  diaglog box and exits.

So how can I determine that CR was entered into my edit box?  

Thanks,
Steve
stevaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nass89Commented:
Hi,
Add PretranslateMessage() as it follows:

BOOL CMyDlg::PreTranslateMessage(MSG* pMsg)
{
      // TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_KEYDOWN)
                              {
      long nID = ::GetDlgCtrlID(pMsg->hwnd);
      if(nID== IDC_EDIT1){ //ID of desired editbox
      if(pMsg->wParam == VK_RETURN)
            return TRUE;//Or anything you want

              }
}

Good Luck!
0
stevaAuthor Commented:
Ok, this looks good.  But where is it called from, and where do I get the pMsg to pass?

Steve
0
SkonenCommented:
PreTranslateMessage is event driven, so you don't need to call it directly from another function. In VC++ just press ctrl+w, and then select the dialog class that contains your edit box control, then select "PreTranslateMessage" from the "messages" list. Then click add function and edit the function body to fit the function given above.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stevaAuthor Commented:
That works fine.  Now when PretranslateMessage() detects CR entered in the edit box it just calls call the button routine that normally picked up the value.

Thanks for the help.  I split the points.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.