?
Solved

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

Posted on 2004-08-30
3
Medium Priority
?
802 Views
Last Modified: 2008-01-09
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.
0
Comment
Question by:mromeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11935064
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);
}
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 11935318
This version could be clearer:

BOOL CYourDlg::PreTranslateMessage(MSG* pMsg)
{
      static char *validchars = "01234567890.-\b";

      if (pMsg->message==WM_CHAR)
            if (!strchr(validchars,pMsg->wParam) && pMsg->hwnd==GetDlgItem(100)->m_hWnd)
                  return TRUE;
      
      return CDialog::PreTranslateMessage(pMsg);
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Six Sigma Control Plans
Starting up a Project
Suggested Courses

752 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