Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls


If an edit box is configured to display an asterisk character and you want to find out what
that character is, call the CEdit::GetPasswordChar(). Its syntax is:

TCHAR GetPasswordChar() const;

This method takes no argument but returns the symbol used to mask the characters of a
password-configured edit box.

By default, an edit box is configure to display or receive text of any alphabetic and non-
alphabetic character. The alphabetical letters are received by their case and kept like that,
uppercase and lowercase. If you want to convert an edit box' characters to uppercase, set
the Uppercase property to True or programmatically add the ES_UPPERCASE style. In
the same way, to convert the characters to lowercase, either at design time set the
Lowercase property to True or programmatically add the ES_LOWERCASE style. The
non-alphabetical characters are not treated by their case.

If you want, you can configure the edit box to allow only numeric characters. This is
done by setting the Number property to True.

By default, the characters entered in an edit box start their positioning to the left, which is
the default for regular text. You can align its value to the center or the right by selecting
the desired value from the Align Text combo box. Any of these three alignment modes
can also be set programmatically by adding either the ES_LEFT, the ES_CENTER, or
the ES_RIGHT style.

As mentioned above, the value of an edit box is of high interest to you and your users. If
you want to retrieve the value of an edit box, call the CWnd::GetWindowText()
method. If you want to display or change the text of an edit box, call the
CWnd::SetWindowText() method. As we have seen in the past, SetWindowText() takes
a constant pointer to null-terminated string (LPCTSTR) and displays its value in the edit.
This method is very convenient if you had add a CEdit variable to your edit control. If
you have added the variable as a CString, you can use the CString::Format() method to
change or format the value to display in an edit box.

Practical Learning: Configuring Edit Boxes



  1. The Clarksville Ice Scream1 application should still be opened
    Using the Add Resource dialog box, add a new dialog:

Free download pdf