CXTMaskEdit::SetEditMask
Copyright © 1998-2025 Codejock Software, All Rights Reserved.

CXTMaskEdit::SetEditMask(
   
LPCTSTR
lpszMask,
   
LPCTSTR
lpszLiteral,
   
LPCTSTR
lpszDefault=NULL)

Parameters:

lpszMask

You can use any of these characters for defining your edit mask:

0 - Numeric (0-9)
9 - Numeric (0-9) or space (' ')
# - Numeric (0-9) or space (' ') or ('+') or ('-')
L - Alpha (a-Z)
? - Alpha (a-Z) or space (' ')
A - Alpha numeric (0-9 and a-Z)
a - Alpha numeric (0-9 and a-Z) or space (' ')
& - All print character only
H - Hex digit (0-9 and A-F)
X - Hex digit (0-9 and A-F) and space (' ')
> - Forces characters to upper case (A-Z)
< - Forces characters to lower case (a-z)

Any of these characters can be combined with additional characters to create a restrictive field for text entry.  For example, if you wanted to display a prompt for a telephone number and wanted to restrict only numeric values, but wanted to display the area code inside of parentheses '(' and ')' then you could define your mask as:

Phone No: (000) 000-0000

lpszLiteral

Literal defines the prompt area of the mask where text entry is allowed.  This should match the areas that you have already defined as mask fields.  By default the prompt character is '_' but you can define this to be any character you want by calling CXTMaskEdit::SetPromptChar( TCHAR ch ):

Phone No: (___) ___-____

lpszDefault

This value is optional, but allows you to define default characters that you want displayed when the user presses the backspace key.  This usually represents data that has been previously saved then restored.  This makes it easy for the user to restore some or all of the default text displayed when the control was initialized.  If left blank, you can simply use SetWindowText to initialize the edit control otherwise the literal character string will be used.  Again, this value should match the previously defined mask:

Phone No: (800) 555-1212

Remarks:

This member function defines the attributes for the mask edit control.

Example:

The following is an example that demonstrates the use of CXTMaskEdit::SetEditMask:

m_maskEdit.SetEditMask(
    _T("Phone No: (000) 000-0000"),
    _T("Phone No: (___) ___-____"),
    _T("Phone No: (800) 555-1212"));


Send feedback to Codejock Software.  Look here for online resources.