Entering only letters in MFC

This is a discussion on Entering only letters in MFC within the Windows Programming forums, part of the Platform Specific Boards category; hey, im doing thisprogram, and in this textfield, i just want the user to enter in only letter, and not ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    11

    Entering only letters in MFC

    hey, im doing thisprogram, and in this textfield, i just want the user to enter in only letter, and not allow them to enter anything in but letters. i know the command for only entering in numbers is ES_NUMBER, but i havent been able to find out how to do that with letters instead of numbers. thanx

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    This should probably have been posted to the Windows forum.
    Derive a new control from CEdit and call it CAlphaEdit. Overload the OnChar() method and check if characters entered were non-char, if so, block them.
    Code:
    class CAlphaEdit : public CEdit
    {
    protected:
        afx_msg void OnChar(UINT, UINT, UINT);
        DECLARE_MESSAGE_MAP()
    };
    
    BEGIN_MESSAGE_MAP(CSsnEdit, CEdit)
        ON_WM_CHAR()
    END_MESSAGE_MAP()
    
    void CAlphaEdit::OnChar(UINT nChar, UINT nRepCount, UINT nFlags)
    {
        if (_istalpha(nChar))
            CEdit::OnChar(nChar, nRepCount, nFlags);
    }
    If you need anything else, or don't understand this example, post back.

  3. #3
    Registered User
    Join Date
    Mar 2003
    Posts
    11
    im havin trouble using it on this one specific text box, i dont know how to do it

  4. #4
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    Are you using MFC? If so, try the solution above, I don't use MFC so I can't vouch for it.

    If you are using the raw API, subclass the edit box and intercept each WM_CHAR message, if it contained a character I wanted, I'd forward the message to the edit box, if not, dump it.

    If you don't know how to do that, post again.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. WIndows programming?
    By hostensteffa in forum Windows Programming
    Replies: 7
    Last Post: 06-07-2002, 08:52 PM
  2. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 06:42 PM
  3. Understanding The Future of MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 04-15-2002, 09:08 PM
  4. Beginning MFC (Prosise) Part III - Now What? :: C++
    By kuphryn in forum C++ Programming
    Replies: 5
    Last Post: 03-03-2002, 05:58 PM
  5. MFC is Challenging :: C++
    By kuphryn in forum C++ Programming
    Replies: 8
    Last Post: 02-05-2002, 12:33 AM

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