CVisValidEdit : Visual Validator
Overview
First, thanks to Joseph M. Newcomer for the initial leg work (see his article on CodeProject for more details).Second, Updating the documentation is becoming a major chore. The first time I posted this control (which I made a boob of & sent in an incorrect version of the control with several errors) I had done a lot of work on the documentation but since it was relevant to the old version, I had to do lots of updating. Hence, I have removed all implementation detail and included it as a download. I have improved a lot of stuff and removed the bugs I knew of.
CVisValidEdit is an edit control with a difference - there is visual cues & validation (both built in & customisable). The edit control offers additional support for displaying & converting several numeric types.
- double < -- > Binary < -- > long
- double < -- > Hexadecimal < -- > long
- double < -- > Octal < -- > long
- double < -- > Float < -- > long
The visual cues are by way of different colour brushes to indicate the error type.
There are numerous options that make this control a
synch to use!
CVisValidEdit Usage...
#include the header "VisValEdit.h" where required.
Add a standard edit control to your dialog.
Using the class wizard, attach a member variable select 'Control' from the category combo & select CVisValidEdit as the variable type (if CvisValidEdit is not in the list, just choose CEdit & change the type in your class definition)
Set any options required before displaying your dialog.
Add functions to handle UWM_VVE_DO_CUSTOMVALIDATION & UWM_VVE_VALIDITY_CHANGED UWM_VVE_CONTENT_CHANGED (follow links for example)
Display your dialog.
CVisValidEdit Functions...
Status requests
BOOL IsValid(); BOOL IsValidLength(); BOOL IsValidSyntax();
Validation requests
void DoValidation(BOOL bRedraw = TRUE);
Set & Get Functions
int CheckRange(); int CheckRange(LPCSTR lpszVal); static int CheckRange(VVEset vveset, LPCSTR lpszVal); static int CheckRange(VVEset vveset, double dVal); void DisplayMoreInfo(BOOL bAddOnExtraInfo = TRUE); void GetMoreInfoString(VVEset vveset, CString &sInfoString, BOOL bAddOnExtraInfo = TRUE ); void SetMoreInfoString(VVEset vveset, LPCTSTR sNewInfoString = NULL );//NULL = reset to default void SetContextInfo(VVEbrush ErrBrush, LPCSTR sErrMesg); void GetContextInfo(VVEbrush ErrBrush, CString &sErrMesg); void GetCurContextInfo(CString &sErrMesg); void SetEnableContextInfo(BOOL bEnable = TRUE); BOOL GetEnableContextInfo(); void SetEnableRangeChecking(BOOL bEnable = TRUE); BOOL GetEnableRangeChecking(); void SetCustomErrorIsValid(int iCustomWhich, BOOL bSetIsValid = TRUE); BOOL GetCustomErrorIsValid(int iCustomWhich, BOOL &bCustomIsValid ); void DoValidation(BOOL bRedraw = TRUE);//explicit request void SetEnableLengthCheck(BOOL bEnable = TRUE); BOOL GetEnableLengthCheck(); BOOL SetBrushColour(VVEbrush brWhich, COLORREF NewColour); COLORREF GetBrushColour(VVEbrush brWhich); BOOL SetWindowValue(double fSetVal); BOOL SetWindowValue(long lSetVal); BOOL SetWindowValue(unsigned long lSetVal); BOOL GetWindowValue(double &fVal);//returns FALSE if string is too large for double BOOL GetWindowValue(long &lVal);//returns FALSE if string is too small/large for long BOOL GetWindowValue(unsigned long &lVal);//returns FALSE if string is too large for ulong BOOL GetAllCharEntry(); void SetAllCharEntry(BOOL bAllowAllCharsIn = TRUE); BOOL GetEmptyValid(); void SetEmptyValid(BOOL bEmptyOK = TRUE); void SetDisableValidation(BOOL bNoValidation = TRUE); BOOL GetDisableValidation(); void SetCustomValidation(BOOL bUseCustom = TRUE); BOOL GetCustomValidation(); void SetValidCharSet(VVEset vveset, LPCTSTR cstrCustomChar = NULL);//NULL = reset to default void SetValidSet(VVEset vveset); VVEset GetValidSet(); void SetValidChars(LPCTSTR cstrCustomChar); void GetValidChars(CString & strValidChars); void SetTextLenMinMax(int iMin = VVE_DEF_MINLEN, int iMax = VVE_DEF_MAXLEN); int GetTextMinLen(); int GetTextMaxLen();
Public Enumerations
enum VVEbrush {BR_ERROR, BR_EMPTY, BR_VALID, BR_INVALIDSYNTAX, BR_INCOMPLETE, BR_SHORT, BR_LONG, BR_RANGEERR, BR_CUSTOM_ERR1, BR_CUSTOM_ERR2}; //return constants - each has a matching brush //(BR_INCOMPLETE, BR_SHORT, BR_LONG, BR_RANGEERR are same brush only context info changes).
enum VVEset {SET_CUSTOM, SET_ALLCHAR, SET_ALPHANUM, SET_ALPHA, SET_DECIMAL, SET_SDECIMAL, //Signed SET_HEXADECIMAL, SET_OCTAL, SET_BINARY, SET_FLOAT };
Notification Messages
UWM_VVE_DO_CUSTOMVALIDATION
- wParam - pointer to a notification message structure MNHDR (code contains enumerated value of current error brush see VVEbrush)
- lParam - const pointer to the widow text
- Return - Expected return is a constant of the VVEbrush enumeration
This message is sent to the parent when custom validation option is set & validation of the input is required. UWM_VVE_DO_CUSTOMVALIDATION can be intercepted by the inclusion of a MESSAGEMAP entry e.g.
In your MESSAGEMAP
ON_MESSAGE(UWM_VVE_DO_CUSTOMVALIDATION, OnDoValidation)In your *.h file
//}}AFX_MSG //below here afx_msg LRESULT OnDoValidation(WPARAM wParam, LPARAM lParam);//add declaration here DECLARE_MESSAGE_MAP() //above here
In your *.cpp file
LRESULT CValidatorDlg:: OnDoValidation(WPARAM wParam, LPARAM lParam)
{
//pointer to an NMHDR structure
LPNMHDR nm = (LPNMHDR) wParam;
//pointer to const string (text in control)
CString s((LPCSTR) lParam);
//regardless of idfrom, this routine says empty is empty
if(s. GetLength() == 0)
return (LRESULT) CVisValidEdit::BR_EMPTY";
//nm contains the idfrom & hwnd from of the control
// requesting validation.
switch(nm-> idFrom)
{
case IDC_SWEAR_WORD_INHIBITING_EDIT_BOX:
if(s.Find("SHIT"))//Word not tolerated - return custom error 1
return CVisValidEdit::BR_CUSTOM_ERR1; //return error
case IDC_A_NAME_EDIT_BOX:
if(s.Find("0123456789") == -1)//No numbers in your name
return CVisValidEdit::BR_CUSTOM_ERR1; //return error
};
}
UWM_VVE_VALIDITY_CHANGED
- wParam - pointer to a notification message structure MNHDR (code contains enumerated value of current error brush see VVEbrush)
- lParam - The new valid state. 0 = Invalid, other = Valid
- Return - void (0)
In your MESSAGEMAP
(in *.cpp file)ON_MESSAGE(UWM_VVE_VALIDITY_CHANGED, OnValidChanged)
In your *.h file
//}}AFX_MSG //below here afx_msg LRESULT OnValidChanged(WPARAM wParam, LPARAM lParam);//add declaration here ok DECLARE_MESSAGE_MAP() //above here
In your *.cpp file
afx_msg LRESULT OnValidChanged(WPARAM wParam, LPARAM lParam)
{
if(((LPNMHDR)wParam)->idfrom == IDOK )
OkButton.EnableWindow(lParam);
}
UWM_VVE_CONTENT_CHANGED
- wParam - pointer to a notification message structure MNHDR (code contains enumerated value of current error seeVVEbrush)
- lParam - The valid state. 0 = Invalid, other = Valid
- Return - void (0)
In your MESSAGEMAP
(in *.cpp file)ON_MESSAGE(UWM_VVE_CONTENT_CHANGED, OnContentChanged)
In your *.h file
//}}AFX_MSG //below here afx_msg LRESULT OnContentChanged(WPARAM wParam, LPARAM lParam);//add declaration here ok DECLARE_MESSAGE_MAP() //above here
In your *.cpp file
afx_msg LRESULT OnContentChanged(WPARAM wParam, LPARAM lParam)
{
LPNMHDR pNM = (LPNMHDR)wParam;
if( pNM ->idfrom == IDC_NAME && pNM->code == CVisValidEdit::BR_EMPTY)
MessageBox("You must enter your name");
}
Downloads
Download source - 13 KbDownload demo project - 28 Kb
Download complete documentation - 47 Kb
Date Posted : March 13 2001
Date Updated: April 2, 2001

Comments
Documentation Zip Missing ?
Posted by kreigle on 03/29/2007 09:40pmThe link is not correct or the file is missing. Clicking on the link takes me to CodeGuru's sitemap page, not the file download.
ReplyDocumentation Zip Correct
Posted by Promotional Engine on 08/22/2006 09:19pmNo problem in download...
ReplyDocumentation Zip Missing
Posted by Legacy on 04/05/2001 12:00amOriginally posted by: Pete Stieber
The link is not correct or the file is missing.
Reply