SECMaskEdit Class

class SECMaskEdit: public CEdit

SECMaskEdit attaches to existing CEdit controls and lets you add formatted input capabilites to them. To use SECMaskEdit, you follow these steps:

1. Attach SECMaskEdit to an existing CEdit using the AttachEdit member function.
2. Set a mask that defines the format of the data to be entered.
3. Call GetData to retrieve the data without the mask, or GetRawData to retrieve the entire contents of the SECMaskEdit.

Defined in: SECMEDIT.H

Comments

SECMaskEdit supports cut, copy, paste and clear. Insert mode is also supported and is toggled on/off when the user presses the ‘VK_INSERT’ key.

Masks consist of ‘mask characters’ and literals. Literals are characters that appear unchanged in the mask, while mask characters specify a spot in the mask edit that accepts certain characters. See SetMask for a list of valid mask characters and examples of popular masks.

At runtime the mask characters are replaced with the prompt character which is a space by default. The prompt character can be changed via the SetPromptChar() member function.

NOTE: In this version of SECMaskEdit, validation is not performed on the various ‘types’ of data. For example, it is up to the SECMaskEdit user to detect that 12/35/95 is an invalid date, because while this data fits the requirements of the mask, it is invalid for a US date format.

Intelligent validation, and DDV capabilities will be added in a future version of SECMaskEdit.

The SECMaskEdit class supports DDX using DDX_Mask.

The MASKTEST sample in the \SAMPLES\TOOLKIT\STANDARD\CONTROLS\MASKTEST directory demonstrates how to use the SECMaskEdit class.

SECMaskEdit()

Constructs a SECMaskEdit object.

BOOL AttachEdit(int nCtlID, CWnd* pParentWnd)

Attaches the SECMaskEdit to an existing CEdit control.

Class Members

Attributes

virtual BOOL SetMask(LPCTSTR lpszMask)

Sets the input mask for the edit control.

virtual void SetPromptChar(TCHAR chNewPrompt )

Sets the prompt character.

virtual TCHAR GetPromptChar()

Retrieves the current prompt character.

virtual BOOL SetData(const CString& strData, int nStartPos = 0, BOOL bInsert = FALSE, BOOL bIgnorePromptChars = TRUE)

Puts data into the masked edit.

virtual void GetData(CString& strData, BOOL bTrim = FALSE)

Retrieves data from the masked edit and strips out the

virtual CString& GetRawData(void)

Retrieves the data from the masked edit with all literal

virtual void SetInsertMode(BOOL bInsert = TRUE)

Sets the insert mode

virtual BOOL InsertMode()

Determines if the edit is in insert mode or not.

Operations

void ClearData(void)

Clears the non-literal data from the masked edit.

virtual BOOL CanUndo()

Determines if the last operation can be undone.

virtual BOOL Undo()

Performs an "undo" on the last operation.

virtual void EmptyUndoBuffer()

Clears the "undo" buffer.

Overrideables

virtual BOOL IsCharValid(int nPos, TCHAR& ch)

Determines if a character is valid for the specified position.

virtual BOOL IsLiteralChar(TCHAR ch)

Determines if a character is a literal character.

virtual BOOL IsMaskChar(TCHAR ch)

Determines if a character is a mask character.

virtual void UpdateDisplayStr()

Updates the string displayed in the control based on the current mask.

virtual void ConvertMaskToDisplayStr(CString strMask,CString& strResult)

Given a mask, returns a displayable string based on the current

virtual void ParseMaskString()

Parses the mask string.

virtual int FindLastFilledDataPos(int nStartPos)

Locates the last filled in data position.

virtual BOOL PushChar(int nStartPos, TCHAR ch, BOOL bRefreshDisplay = TRUE)

Inserts a character, and optionally refreshes the display.

virtual void PullChar(int nFromPos, int nToPos)

Removes a range of characters.

virtual int SetCursorPos(int nOldPos, int nDirection, BOOL bSelect = FALSE)

Sets the cursor position.

virtual int GetNextDataPos(int nOldPos)

Retrieves the next data position relative to a given position.

virtual int GetPrevDataPos(int nOldPos)

Retrieves the previous data position relative to a given position.

virtual void UpdateDisplay()

Redraws the control.

Overrides

Protected data members

CString m_strMask

The mask string.

CString m_strDisplay

The displayed string.

TCHAR m_chPrompt

The prompt character (default = space)

BOOL m_bKeyProcessed

Signals OnChar that a key was already handled.

BOOL m_bInsert

Insert mode flag (default = overwrite).

CString m_strUndoText

The undo buffer.

CString m_strRedoText

The redo buffer.