CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2004
    Posts
    1

    Question How to filter some keys in Edit control

    I need a solution to restrict my Edit Box to accept only 0 to 9 and A,B, C, D, E, F key strokes.
    Please advice

  2. #2
    Join Date
    Jun 2004
    Posts
    1,352
    You have to SUBCLASS the edit control.


    Derive a class from CEDIT , call it HEXEDIT and then create a message handle for the WM_CHAR message: use class wizard.

    .... anyhow look up "SUBCLASSING CEdit" on google and I'm sure you'll figure it out!!

  3. #3
    Join Date
    May 2004
    Location
    Germany
    Posts
    655
    ADSOFT is right.
    but if you don't wont to do this on your own (or if you don't know how )

    try this article:

    http://www.codeguru.com/Cpp/controls...icle.php/c539/

    good luck
    there are 10 kinds of people. those who understand binary and those who don't...

    rate a post if you find it usefull, thx
    check out my Firefox/Mozilla Extension: http://urlparams.blogwart.com/

  4. #4
    Join Date
    Jun 2004
    Posts
    2
    It can be solved if you understand the keyborad message& character message translation

  5. #5
    Join Date
    Feb 2002
    Posts
    3,788

    Re: How to filter some keys in Edit control

    Originally posted by Bizybs
    I need a solution to restrict my Edit Box to accept only 0 to 9 and A,B, C, D, E, F key strokes.
    Please advice
    see attached class.
    Attached Files Attached Files

  6. #6
    Join Date
    Jan 2004
    Posts
    58
    There is another solution to this problem
    do the following-

    1. Add a function for the EN_UPDATE Message for the Edit Control
    2. In the OnUpdate function get the character just typed say ch
    3. isxdigit(ch) can be used to verify that it is a digit 0-9, A-F.

    That should work.

    actually I had asked the same question. read it.
    thread
    Last edited by meisunknown; June 21st, 2004 at 03:55 AM.

  7. #7
    Join Date
    Jan 2004
    Location
    Punjab, India
    Posts
    113
    Must keep in mind that cut, copy, paste are supported by edit box. So, you must validate the whole new text added not just last character in OnUpdate handler.

    Amit

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured