Link to home
Start Free TrialLog in
Avatar of mromeo
mromeo

asked on

How to restrict CEdit to all number types...including negative numbers

Hi.  I want to restrict my CEdit box to numeric values only, but I also want to allow negative numbers.  Using the ES_NUMBER flag doesn't allow anything below 0.  Anybody know if there is a way to do this with a flag or do I need to make it a regular CEdit and check the values myself?
Thanks.
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Insert a PreTranslateMessage event in your dialog:

BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
      if (pMsg->message==WM_CHAR)
            if (!isdigit(pMsg->wParam) && pMsg->wParam!='-' && pMsg->hwnd==GetDlgItem(YOUR_CONTROL_ID)->m_hWnd)
                  return TRUE;
      
      return CDialog::PreTranslateMessage(pMsg);
}
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial