Windows Edit Control Styles
Windows Predefined Controls – Part 4
Volume - Windows User Interface
Forward: In this part of the series, we look at the styles for the edit control.
By: Chrysanthus Date Published: 29 Aug 2012
Introduction
Note: If you cannot see the code or if you think anything is missing (broken link, image absent), just contact me at forchatrans@yahoo.com. That is, contact me for the slightest problem you have about what you are reading.
Presentation of an Edit Control
The presentation and outward behavior of an edit control depends of the styles you use for the edit control.
An Edit control style identifier (constant) begins with ES_. The identifier for a style of a window in general terms, begins with WS_. In the previous part of the series, I indicated that, if you want a multi-line edit control you would type as a minimum, the following in the window style argument, dwStyle of the CreateWindowEx function:
WS_CHILD|ES_MULTILINE
Here, WS_CHILD is a general windows style, while ES_MULTILINE is an edit control style. All the styles we shall learn in this tutorial are edit control styles and they begin with ES_.
So, you can combine windows styles and edit control styles with the | operator in the dwStyle argument of the CreateWindowEx function. | means and/or at that position. You can have more than one edit control style for an edit control.http://localhost/write.htm
If you want a multi-line edit control then you need to include the ES_MULTILINE style with the edit styles (like above). The width and height of the multi-line edit control are determined by the “int nWidth” and “int nHeight” parameters, which are the seventh and eight parameters of the CreateWindowEx function. We saw an example of the use of these in the previous part of the series for a single-line edit control. If the value of the “int nHeight” parameter (argument) is high, then you will be able to see a number of lines in the multi-line edit control. Note: an absence of ES_MULTILINE means you would have a single-line edit control.
For the rest of this tutorial, we look at the edit control styles.
Scrolling Styles
The ES_AUTOHSCROLL style tells the edit control to scroll the text horizontally, when necessary, as the user enters text. With this, the user can type more text for one line, than would fit in one line. This style applies to both the single-line and multi-line edit controls. The ES_AUTOVSCROLL style tells the edit control to scroll the text vertically when the user enters more text than can be displayed in the edit control. This style applies only to multi-line edit controls.
Note: the ES_AUTOHSCROLL and ES_AUTOVSCROLL styles do not necessarily provide scroll bars. If you want a horizontal scroll bar for your multi-line edit control, you would have to add the windows style, WS_HSCROLL to the dwStyle argument of the CreateWindowEx function. If you want a vertical scroll bar for your multi-line edit control, you would have to add the windows style, WS_VSCROLL.to the dwStyle argument of the CreateWindowEx function. So if you want a multi-line edit control with vertical and horizontal scroll bars, you would type the following for the dwStyle argument of the CreateWindowEx function:
WS_CHILD|WS_VSCROLL|WS_HSCROLL|ES_MULTILINE
WS_VSCROLL implements the ES_AUTOVSCROLL style for an edit control. WS_HSCROLL implements the ES_AUTOHSCROLL style for an edit control. So with WS_VSCROLL, you do not need ES_AUTOVSCROLL in the dwStyle argument. Also, with WS_HSCROLL you do not need ES_AUTOHSCROLL in the dwStyle argument.
There are three alignment styles: ES_LEFT for left alignment (left justification); ES_CENTER for center alignment (center justification); and ES_RIGHT for right alignment (right justification). There is no style for full justification for the edit control.
Text and Input Styles
Lower and upper case: With the ES_LOWERCASE any character typed on the keyboard, whether in upper or lower case enters the edit control in lowercase. Also, with the ES_UPPERCASE style, any character typed on the keyboard, whether in upper or lower case enters the edit control in uppercase.
Numbers: With the ES_NUMBER style only digits can be entered into the edit control.
Read-only: You can make a control read-only. This means the user can only read what is there and not write (type) into the control. To do this, use the ES_READONLY style.
Password: If you use the ES_PASSWORD style, any character typed on the keyboard will appear in the edit control as an asterisk. Asterisk is the default password character. If you do not want the asterisk, use the EM_SETPASSWORDCHAR message (see later) to have a different password character.
The ES_WANTRETURN style: As the user is typing into a multi-line edit control, he would press the Enter key on the keyboard to continue typing on the next line. If the complete typed text is sent to another computer, it may not be displayed with the lines demarcated the way they were typed. For the lines to be preserved as typed when the Enter key is pressed, they need to end with rn, which are not seen in the edit control. For you to have the unseen r and n characters at the end of each line, use the ES_WANTRETURN style; these unseen characters will be inserted when the user presses the Enter key.
There are two other styles for the edit control that I have not mentioned. These are the ES_NOHIDESEL and ES_OEMCONVERT styles. They are not commonly used so I will not address them in this series.
That is it for this part of the series. We stop here and continue in the next part.
Chrys
Related Courses
C++ CourseRelational Database and Sybase
Windows User Interface
Computer Programmer – A Jack of all Trade – Poem
NEXT