Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-30
3
Medium Priority
?
826 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

610 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