As noted earlier, you create an edit control using ”edit“ as the window class in the CreateWindow call. The window style is WS_CHILD plus several options. As in static child window controls, the text in edit controls can be either left-justified, right-justified, or centered. You specify this formatting with the window styles ES_LEFT, ES_RIGHT, and ES_CENTER.
By default, an edit control has a single line. You can create a multiline edit control with the window style ES_MULTILINE. For a single-line edit control, you can normally enter text only to the end of the edit control rectangle. To create an edit control that automatically scrolls horizontally, you use the style ES_AUTOHSCROLL. For a multiline edit control, text wordwraps unless you use the ES_AUTOHSCROLL style, in which case you must press the Enter key to start a new line. You can also include vertical scrolling in a multiline edit control by using the style ES_AUTOVSCROLL.
When you include these scrolling styles in multiline edit controls, you might also want to add scroll bars to the edit control. You do so by using the same window style identifiers as for nonchild windows: WS_HSCROLL and WS_VSCROLL.
By default, an edit control has no border. You can add one by using the style WS_BORDER.
When you select text in an edit control, Windows displays it in reverse video. When the edit control loses the input focus, however, the selected text is no longer highlighted. If you want the selection to be highlighted even when the edit control does not have the input focus, you can use the style ES_NOHIDESEL.
When POPPAD1 creates its edit control, the style is given in the CreateWindow call as:
WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
WS_BORDER | ES_LEFT | ES_MULTILINE |
ES_AUTOHSCROLL | ES_AUTOVSCROLL
In POPPAD1 the dimensions of the edit control are later defined by a call to MoveWindow when WndProc receives a WM_SIZE message. The size of the edit control is simply set to the size of the main window:
MoveWindow (hwndEdit, 0, 0, LOWORD (lParam),
HIWORD (lParam), TRUE) ;
For a single-line edit control, the height of the control must accommodate the height of a character. If the edit control has a border (as most do), use 1-1/2 times the height of a character (including external leading).