Solved

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

Posted on 2004-08-30
3
723 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
  • 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 125 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This is an explanation of a simple data model to help parse a JSON feed
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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 …

746 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now