8.4.5 Edit Controls

An edit control is a rectangular child window in which the user can type and edit text. Edit controls have a variety of features, such as multiline editing and scrolling. You specify the features you want by specifying a control style.

Edit control styles define how the control will appear and operate. For example, the ES_MULTILINE style creates an edit control in which you can type more than one line of text. The styles ES_AUTOHSCROLL and ES_AUTOVSCROLL direct the control to scroll horizontally or vertically if the user types more text than can fit in the control's client area. If these styles are not specified and the user types more text than can fit on one line, the text wraps to the next line if the control is a multiline edit control. You can also use the WS_HSCROLL and (for a multiline edit control) WS_VSCROLL styles to allow the user to scroll the text in the control.

Your application can use an edit control in which a user can type a password or other private text without displaying what is typed. The ES_PASSWORD style creates an edit control that does not display text as the user types it; instead, the control displays an arbitrary character for each character that the user types. By default, this character is an asterisk (*). To change the character displayed by the control, send the EM_SETPASSWORDCHAR message to the control.

You can set tab stops in a multiline edit control by sending the EM_SETTABSTOPS message to the control. This message specifies the number of tab stops the control should contain and the distances between the tab stops.

An edit control sends notification messages to its parent window. For example,
it sends an EN_CHANGE message when the user makes a change to the text.
An edit control can also receive messages, such as EM_GETLINE and EM_LINELENGTH. The control carries out the specified action when it receives a message.

A powerful feature of edit controls is the ability to “undo” a change to its contents. To determine whether an edit control can undo an action, send it the EM_CANUNDO message; the control will return a nonzero value if it can undo the last change. If the control can undo the change, your application can send the EM_UNDO message to the control to reverse the last change made to it.