Accepting only 0-9 + -. in an EDIT box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am making a simple program for Windows in C++ . I need some of the EDIT controls to accept only numbers- i.e. the user should NOT be able to enter letters or other unnecessary symbols. However, the user may have to enter fractions and negative numbers ,therefore +, -, and . should be enabled

I suppose this could be achieved with the ActiveX Microsoft MaskedEdit Control. However, I am not sure how exactly to use the mask. I want the decimal dot to be optional if possible, and to limit the number of digits after the deciaml dot to 2

I intend to use Windows API in my program, but I may also use the MFC if its considerably easier

Thank you for your replies in advance.
 
hi,

there are two ways to do this:

1.: use the DDX_Text (pDX, ID, integer of float) in dodataexchange

2.: in pretranslate message of the edit control catch the wm_char.
is wparam is one of the not allowed chars, return true
 
Back
Top