Controlling edit control input

This is a discussion on Controlling edit control input within the Windows Programming forums, part of the Platform Specific Boards category; I have a series of edit controls which I only want to accept numbers. I looked at msdn's edit control ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    36

    Controlling edit control input

    I have a series of edit controls which I only want to accept numbers. I looked at msdn's edit control messages but I only see messages where I cannot see the data being entered into the control, but just that the edit control has been / will be updated. I was hoping for a message with the destination edit control reference and the data to be input and that I could just return from the message handler if I do not want to accept certain input.

    Any tips?

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,266
    Edit controls have the ES_NUMBER style available which only allows numeric input. Beyond that, you would probably need to subclass the control.

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    ...and you can do that with SetWindowLong().

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    36
    Thanks, works good now!

  5. #5
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Quote Originally Posted by Gerread View Post
    I was hoping for a message with the destination edit control reference and the data to be input and that I could just return from the message handler if I do not want to accept certain input.

    Any tips?
    The WM_COMMAND msg type 'EN_CHANGE' msg will be sent each character typed into an edit.

    EN_ is Edit Notification
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  6. #6
    Registered User pronecracker's Avatar
    Join Date
    Oct 2006
    Location
    netherlands
    Posts
    158
    ...But when you receive EN_CHANGE the data has already changed. The edit control doesn't ask you if you want to accept a character. If ES_NUMBER does not do what you want, you need to create a custom win proc for the edit control on top of the standard edit control proc.

  7. #7
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Quote Originally Posted by pronecracker View Post
    ...But when you receive EN_CHANGE the data has already changed. The edit control doesn't ask you if you want to accept a character. If ES_NUMBER does not do what you want, you need to create a custom win proc for the edit control on top of the standard edit control proc.
    Actually the EN_CHANGE is ent after the data has changed but prior to the edit being redraw. So the change is yet to appear on the users screen.

    Keep the acceptable / current data in a buffer.

    When you get an EN_CHANGE, process the difference between the acceptable data and the text in the EDIT (ie the new input).

    If the new input (the difference) is acceptable, add it to the buffer.
    If the new input is not acceptable, copy the buffer back to the edit (thus removing the new input).

    You will get an EN_CHANGE for each character entered.

    I do this all the time to allow float / currency input.
    Last edited by novacain; 05-03-2007 at 09:58 PM.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can't disable ctrl-V on a rich edit control
    By rakan in forum Windows Programming
    Replies: 1
    Last Post: 02-06-2008, 08:37 AM
  2. Buttons + Edit Control
    By jay kay in forum Windows Programming
    Replies: 6
    Last Post: 03-09-2005, 05:36 PM
  3. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 10:44 AM
  4. Controlling an edit control
    By master5001 in forum Windows Programming
    Replies: 2
    Last Post: 10-16-2001, 04:08 PM
  5. Rich edit control example Win API
    By Echidna in forum Windows Programming
    Replies: 1
    Last Post: 09-17-2001, 03:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21