Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

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
0
steva
Asked:
steva
  • 2
2 Solutions
 
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
 
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now