Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Edit Box Character Test (Input Filter)

Edit Box Character Test (Input Filter)

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Freddie Code
    wrote on last edited by
    #1

    I'm trying to filter the characters that are typed into an edit box. For example, I only want the characters A,B,C,D,E,F to be allowed to be typed into the box. Any other characters typed will not be displayed in the box. Does anyone know how to do this? Thanks, Freddie

    P M 2 Replies Last reply
    0
    • F Freddie Code

      I'm trying to filter the characters that are typed into an edit box. For example, I only want the characters A,B,C,D,E,F to be allowed to be typed into the box. Any other characters typed will not be displayed in the box. Does anyone know how to do this? Thanks, Freddie

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #2

      Basically you customise the edit control. Derive a class from the CEdit and listen to the keyboard inputs if they are not amoung the charecters that you want then ignore them. There are lot of these types of controls here in the codeproject. You can follow the link for CEdit on the leftside at www.codeproject.com


      This space is empty.

      1 Reply Last reply
      0
      • F Freddie Code

        I'm trying to filter the characters that are typed into an edit box. For example, I only want the characters A,B,C,D,E,F to be allowed to be typed into the box. Any other characters typed will not be displayed in the box. Does anyone know how to do this? Thanks, Freddie

        M Offline
        M Offline
        monrobot13
        wrote on last edited by
        #3

        Here's a quick and dirty implementation:

        // in CMyEdit.h
        afx_msg void OnChar (UINT nChar, UINT nRepCnt, UINT nFlags);
        DECLAR_MESSAGE_MAP()

        // in CMyEdit.cpp

        BEGIN_MESSAGE_MAP(CMyEdit, CEdit)
        ON_WM_CHAR ()
        END_MESSAGE_MAP()

        void CMyEdit::OnChar (UINT nChar, UINT nRepCnt, UINT nFlags)
        {
        int lwr = tolower (nChar);

        if (lwr >= 'a' && lwr <= 'f' && lwr != '.' ||
            lwr == VK\_BACK || lwr == VK\_DELETE
           )
            CEdit::OnChar (nChar, nRepCnt, nFlags)
        

        }

        Then add a control variable for the editbox and in your .h file change it's type to CMyEdit instead of CEdit. Not the best way to do it, but you could get by with it. - Aaron

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups