Thread: Validate an edit control

  1. #1
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310

    Validate an edit control

    Hi!

    How do you guys validate an edit control to accept only some chars?
    I have a theory about it...

    1.- subclass the edit control
    2.- trap the WM_KEYPRESS or WM_CHAR
    3.- test the character stroke.

    is this the proper way?

    Additional: I'm trying to accept only the following chars: 0-9 and .
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Try this...

    Code:
    CreateWindow("EDIT",NULL,
             WS_CHILD | WS_VISIBLE | WS_TABSTOP |
             ES_NUMBER | ES_CENTER,
             0,0,100,30,hParent,NULL,hInstance,NULL);

  3. #3
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    639
    Use EN_UPDATE and scan for any illegal chars, you can use ES_NUMBER but it doesn't allow decimal separators to be entered. Either way, you have to do some additional work.

  4. #4
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by adeyblue View Post
    you can use ES_NUMBER but it doesn't allow decimal separators
    Well, I'll be... you learn something new every day.

  5. #5
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Thanks, I'll try EN_UPDATE
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. edit control - entering only numbers
    By Micko in forum Windows Programming
    Replies: 2
    Last Post: 08-20-2004, 11:31 AM
  4. Appending text to an edit control
    By dit6a9 in forum Windows Programming
    Replies: 3
    Last Post: 08-13-2004, 09:52 PM
  5. endless edit control
    By ZerOrDie in forum Windows Programming
    Replies: 3
    Last Post: 03-21-2003, 02:51 AM