Click here to Skip to main content
12,511,553 members (48,630 online)
Click here to Skip to main content

Stats

121.6K views
2.4K downloads
34 bookmarked
Posted

Enhanced Focus Edit Control with Input Filtering

, 3 Oct 2000 CPOL
An edit control that provides strong visual feedback when it has the input focus, and allows filtering of input and/or displayed characters.
#if !defined(AFX_FOCUSEDITCTRL_H__9CECF3E6_5C4C_11D2_90CC_00104B2C8FCC__INCLUDED_)
#define AFX_FOCUSEDITCTRL_H__9CECF3E6_5C4C_11D2_90CC_00104B2C8FCC__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/*|*\
|*|  File:      FocusEditCtrl.h
|*|  
|*|  By:        James R. Twine, Rubin And Associates, Inc.
|*|             Copyright 1988, Rubin And Associates, Inc.
|*|  Date:      Friday, October 09, 1998
|*|             
|*|             This implementes an Edit Control that provides
|*|             a custom background color to indicate focus.
|*|             (This class uses static variables for the colors,
|*|             so all controls that uses this class will use the
|*|             same colors).
|*|				Portions of this code are derived from CDropEdit
|*|				by Chris Losinger.  (See comments below)
|*|             
|*|             These Changes May Be Freely Incorporated Into 
|*|             Projects Of Any Type Subject To The Following 
|*|             Conditions:
|*|             
|*|             o This Header Must Remain In This File, And Any
|*|               Files Derived From It
|*|             o Do Not Misrepresent The Origin Of Any Parts Of 
|*|               This Code (IOW, Do Not Claim You Wrote It)
|*|             
|*|             A "Mention In The Credits", Or Similar Acknowledgement,
|*|             Is *NOT* Required.  It Would Be Nice, Though! :)
|*|             
|*|  Revisions: 
|*|             xx/xx/99 Incorporated The Ability To "Filter" The Input.
|*|	
\*|*/
//	CDropEdit
//	Copyright 1997 Chris Losinger
//
//	This code is freely distributable and modifiable, as long as credit
//	is given to where it's due. Watch, I'll demonstrate :
//
//	shortcut expansion code modified from :
//	CShortcut, 1996 Rob Warner

/////////////////////////////////////////////////////////////////////////////
// CFocusEditCtrl window

class CFocusEditCtrl : public CEdit
{
// Construction
public:
	CFocusEditCtrl();
	void	EnableFileDropping( bool bEnable = true );		// Enable Files To Be Dropped

	//
	//	The Exclude Mask Should Be A String Of Characters
	//	To PREVENT The Entry Of.
	//
	void	SetExcludeMask( LPCTSTR cpMask = NULL );		// Set/Clear The Exclude Mask

	//
	//	The Include Mask Should Be A String Of Characters
	//	To ALLOW The Entry Of.
	//
	void	SetIncludeMask( LPCTSTR cpMask = NULL );		// Set/Clear The Include Mask

	//
	//	Use This Function To Remove Invalid Characters From 
	//	A String *BEFORE* Using SetWindowText(...).
	//
	void	StripFilteredChars( LPTSTR cpBuffer );			// Remove Bad Characters From Specified String

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFocusEditCtrl)
	public:
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CFocusEditCtrl();

	// Generated message map functions
protected:
	//{{AFX_MSG(CFocusEditCtrl)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnDropFiles(HDROP dropInfo);
	afx_msg HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg BOOL OnKillFocusReflect();
	afx_msg BOOL OnSetFocusReflect();
	//}}AFX_MSG

	afx_msg	LRESULT	OnPaste( WPARAM, LPARAM );				// Overidden Paste Handler
	afx_msg	LRESULT	OnCut( WPARAM, LPARAM );				// Overidden Cut Handler
	afx_msg	LRESULT	OnCopy( WPARAM, LPARAM );				// Overidden Copy Handler
	afx_msg	LRESULT	OnClear( WPARAM, LPARAM );				// Overidden Delete Handler
	afx_msg	LRESULT	OnUndo( WPARAM, LPARAM );				// Overidden Undo Handler
//	afx_msg	LRESULT	OnSelectAll( WPARAM, LPARAM );			// Overidden Select All Handler

	DECLARE_MESSAGE_MAP()

	CString	m_sExcludeCharMask;								// Exclusion Character Mask
	CString	m_sIncludeCharMask;								// Inclusion Character Mask
	CBrush	m_brBGBrush;									// Background Brush
	bool	m_bExcludeMask;									// Exclude Mask Flag
	bool	m_bIncludeMask;									// Include Mask Flag

	private:
		CFocusEditCtrl(const CFocusEditCtrl& rSrc);
		CFocusEditCtrl&		operator = (const CFocusEditCtrl& rSrc);
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_FOCUSEDITCTRL_H__9CECF3E6_5C4C_11D2_90CC_00104B2C8FCC__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

James R. Twine
President JRTwine Software, LLC
United States United States
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

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 4 Oct 2000
Article Copyright 2000 by James R. Twine
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid