Solved

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

Posted on 2004-08-30
3
756 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i compile this github project?? 2 91
Please explain: Aspect Oriented Programming 2 101
Advice on Xojo as a development tool over VB. 4 71
Query Syntax 17 43
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

830 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