Click here to Skip to main content
6,634,665 members and growing! (19,072 online)
Email Password   helpLost your password?
Desktop Development » Edit Controls » Masked and Validating controls     Intermediate

Enhanced Focus Edit Control with Input Filtering

By James R. Twine

An edit control that provides strong visual feedback when it has the input focus, and allows filtering of input and/or displayed characters.
VC6Win2K, MFC, Dev
Posted:21 Sep 2000
Updated:3 Oct 2000
Views:93,299
Bookmarked:25 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 5.29 Rating: 4.39 out of 5
1 vote, 16.7%
1

2

3
3 votes, 50.0%
4
2 votes, 33.3%
5
  • Download demo project -�4 Kb
  • Download source -�19 Kb

    This article describes�a class (CFocusEditCtrl) for an Enhanced Focus Edit Control with filtering capability.� This control serves two purposes.� First, it provides visual feedback when it has focus by changing it's background color.� Second, it supports the filtering of input.

    The visual feedback is useful when the control is used on a crowded interface, and redesign of the interface is not possible.� On crowded interfaces, it is often easy to "lose" the caret, and the user is unable to tell which edit control (if any) has the input focus.� The changed background color solves that problem.

    The filtering is useful for when you need a control that accepts only numeric values for input.� A numeric-style edit control does not work correctly here, because it does not allow characters like "+", "-" and "." (decimal point).� This control allows you to specify either a set of�valid characters OR a set of invalid characters.� The filtering also works on a Paste operation.

    It is important to mention that this control only provides validation on a character-by-character basis.� That means that while it can�prevent characters that are not used to specify numeric values, it cannot enforce the proper format of said value.� For example, limiting to numeric value characters does not prevent a string like "123.456.7890" from getting entered (even though it is technically an invalid numeric value).

    Functions of interest are:

    • void EnableFileDropping(�bool bEnable = true )
    • void SetExcludeMask(�LPCTSTR cpMask = NULL )
    • void SetIncludeMask(�LPCTSTR cpMask = NULL )
    • void StripFilteredChars( LPTSTR cpBuffer )

    The EnableFileDropping(...) function is used to allow the edit control to accept a draggeg item, and allow it to be dropped.� This can be useful for getting a file path.

    The SetExcludeMask(...) function allows you to specify a set of characters that are�not to be allowed into the control.� For example, an exclude mask of "1234567890" prevents numeric data from being entered into the control.

    The SetIncludeMask(...) function allows you to specify a set of characters that are allowed to be in the control.� For example, an include mask of "1234567890-+." allows only the entry of numeric data.

    The StripFilteredChars(...) function allows you remove "bad" characters from the passed string.� Do this before calling SetWindowText(...) with any string.

    In the demo image above, the edit control that has the input focus is clearly indicated, and the other two controls are setup to allow only certain data.� Running the app is more useful that my talking about it! :)

    Conditions of use are detailed in the header and source file(s).

    Feel free to contact me if there are any questions.� Have fun.

  • License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    James R. Twine


    Member
    Programming since the age of 10, started professionally at the age of 17. Currently involved in both Client and Server side development on Win32 platforms for MC/HA/FT financial applications. Development experience with Win32, Win16, Linux and other flavors of Unix.

    Extensive multithreaded development experience on Windows platforms using the Win32 SDK, and MFC.

    Experience with HA/FT n-tiered Client/Server systems as well as GUI apps of varying complexity. Some experience with Game developement.

    Having learned that the stuff you can barely get away with doing Client-side apps just does not cut it in the real "Server World", I am amazed how many 'professionals' cannot tell the difference between "works" and "correct" or try to (mis)use VB and/or MFC on server-side development projects, never considering that just because it RUNS, does not mean it runs WELL.

    Lastly, I am also a collector of arcade games, and can perform repairs, conversions, etc. Search for my name, you will find me on lots of arcade-related documents and sites.

    Sites of interest(?):
    http://www.jrtwine.com
    http://www.jrtwine.com/jtwine
    http://www.signingtime.com
    http://www.deletefxpfiles.com
    http://www.checkfavorites.com
    http://www.coinop.org
    Occupation: President
    Company: JRTwine Software, LLC
    Location: United States United States

    Other popular Edit Controls articles:

    Article Top
    You must Sign In to use this message board.
    FAQ FAQ 
     
    Noise Tolerance  Layout  Per page   
     Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
    GeneralCTRL+V doesn't work Pinmembervjairam10:13 3 Mar '06  
    AnswerRe: CTRL+V doesn't work PinmemberJames R. Twine4:17 16 Jun '06  
    GeneralCEdit PinsussAmorevieta4:10 18 Oct '05  
    GeneralRe: CEdit PinmemberJames R. Twine11:42 22 Oct '05  
    Generalhow do i setfocus? Pinmembermpallavi23:27 21 Mar '05  
    GeneralRe: how do i setfocus? PinmemberJames R. Twine12:34 22 Mar '05  
    GeneralRe: small difficulty Pinmembermpallavi19:14 29 Mar '05  
    GeneralRe: small difficulty PinsussAmorevieta3:07 18 Oct '05  
    GeneralNice article - very small issue PinmemberTom Archer8:51 24 Aug '03  
    GeneralRe: Nice article - very small issue PinmemberJames R. Twine9:19 24 Aug '03  
    GeneralCompile errors PinmemberJockeP23:17 2 Apr '03  
    GeneralRe: Compile errors PinmemberJames R. Twine5:49 3 Apr '03  
    Generalpasting to masked edit Pinmembervadim_zhukovsky0:22 17 Feb '03  
    GeneralRe: pasting to masked edit PinmemberJames R. Twine3:57 17 Feb '03  
    GeneralRe: pasting to masked edit PinmemberVadim Zhukovsky21:08 17 Feb '03  
    GeneralRe: pasting to masked edit Pinmembersb14234:54 17 Oct '03  
    GeneralCan paste when readonly. PinmemberHans-Georg Ulrich0:48 6 Aug '01  
    GeneralRe: Can paste when readonly. PinmemberJames R. Twine10:22 7 Aug '01  
    GeneralRe: Can paste when readonly. PinmemberZele2:41 9 Jan '04  
    GeneralProject File Missing. PinsussKevin Gutteridge6:55 4 Oct '00  
    GeneralFixed (was: Project File Missing.) PinsussChris Maunder7:27 4 Oct '00  
    GeneralRe: Fixed (was: Project File Missing.) PinsussKevin Gutteridge7:50 4 Oct '00  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 3 Oct 2000
    Editor: Chris Maunder
    Copyright 2000 by James R. Twine
    Everything else Copyright © CodeProject, 1999-2009
    Web22 | Advertise on the Code Project