Click here to Skip to main content
15,896,201 members
Articles / Desktop Programming / MFC

A Validating Edit Control

Rate me:
Please Sign up or sign in to vote.
4.20/5 (5 votes)
3 Nov 2000 127.3K   1.6K   37  
A very informative, user-oriented validation edit control.
#if !defined(AFX_FLOATINGEDIT_H__7DC36E2E_AE1D_11D4_A002_006067718D04__INCLUDED_)
#define AFX_FLOATINGEDIT_H__7DC36E2E_AE1D_11D4_A002_006067718D04__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// FloatingEdit.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CFloatingEdit window

class CFloatingEdit : public CEdit
{
// Construction
public:
	CFloatingEdit();

// Attributes
public:
   BOOL IsValid() {return SyntaxValid && ValueValid; };
   BOOL IsSyntaxValid() { return SyntaxValid; }
   BOOL IsValueValid()  { return ValueValid; }
   /****************************************************************************
   *                               UWM_CHECK_VALUE
   * Inputs:
   *       WPARAM: MAKELONG(GetDlgCtrlID(), EN_CHANGE)
   *	LPARAM: (LPARAM)(HWND): Window handle
   * Result: BOOL
   *       TRUE if value is acceptable
   *	FALSE if value has an error
   * Effect: 
   *       If the value is FALSE, the window is marked as an invalid value
   *	If the value is TRUE, the window is marked as a valid value
   * Notes:
   *	This message is sent to the parent of the control as a consequence
   *	of the EN_CHANGE notification, but only if the value is syntactically
   *	correct. It may be sent at other times as well
   ****************************************************************************/
   static UINT UWM_CHECK_VALUE;

   /****************************************************************************
   *                              UWM_VALID_CHANGE
   * Inputs:
   *       WPARAM: (WPARAM)MAKELONG(GetDlgCtrlID(), BOOL) Flag indicating new valid state
   *       LPARAM: Window handle of child window
   * Result: LRESULT
   *       Logically void, 0, always
   * Effect: 
   *       Notifies the parent that the validity of the input value has changed
   ****************************************************************************/
   static UINT UWM_VALID_CHANGE;
// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CFloatingEdit)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CFloatingEdit();

	// Generated message map functions
protected:
        CBrush errorBrush;
	CBrush partialBrush;
	CBrush emptyBrush;
	CBrush OKBrush; 
	CBrush * Check();
	BOOL SyntaxValid;
	BOOL ValueValid;
	//{{AFX_MSG(CFloatingEdit)
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG
        afx_msg HBRUSH CtlColor(CDC * dc, UINT id);
	afx_msg BOOL OnChange();
	DECLARE_MESSAGE_MAP()
};



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

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

#endif // !defined(AFX_FLOATINGEDIT_H__7DC36E2E_AE1D_11D4_A002_006067718D04__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 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


Written By
Retired
United States United States
PhD, Computer Science, Carnegie Mellon University, 1975
Certificate in Forensic Science and the Law, Duquesne University, 2008

Co-Author, [i]Win32 Programming[/i]

Comments and Discussions