Click to See Complete Forum and Search --> : edit box that only accepts numbers?


flyingcowofdoom
April 21st, 2005, 04:11 PM
Hi,

I would like to make an edit box that will only accept numerical characters without using MFC. I know that I can do it by checking the EN_UPDATE message and getting the window's text, but I was wondering if there was a way to check each keystroke and cancel it if it is non-numeric. Didn't know if there was an easy way to do this. TIA!

--Chris

Bond
April 21st, 2005, 04:19 PM
You should be able to subclass the edit control easily enough and restrict anything but numbers.

Here is an article from MSDN that does something almost identical. Scroll down to where it says Subclassing a Window:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/windowprocedures/usingwindowprocedures.asp

Better yet, this guy shows you how to do exactly what you're looking for:
http://www.codeproject.com/dialog/ownrdrwsubcls.asp

flyingcowofdoom
April 22nd, 2005, 08:38 AM
Thanks for your help, but I found a better way. The class style ES_NUMBER. Heh.

--Chris

Bond
April 22nd, 2005, 08:43 AM
Thanks for your help, but I found a better way. The class style ES_NUMBER. Heh.

--Chris
Ah, yes! You never want to overlook the completely obvious! :)