BOOL Create( DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID );
dwStyle
Specifies the edit control's style.
rect
Specifies the edit control's size and position.
pParentWnd
Specifies the edit control's parent window (usually a CDialog or CModalDialog). It must not be NULL.
nID
Specifies the edit control's ID.
You construct a CEdit object in two steps. First, call the CEdit constructor, then call Create, which creates the Windows edit control and attaches it to the CEdit object.
When Create executes, Windows sends the WM_NCCREATE, WM_NCCALCSIZE, WM_CREATE, and WM_GETMINMAXINFO messages to the edit control.
These messages are handled by default by the OnNcCreate, OnNcCalcSize, OnCreate, and OnGetMinMaxInfo member functions in the CWnd base class. To extend the default message handling, derive a class from CEdit, add a message map to the new class, and override the above message-handler member functions. Override OnCreate, for example, to perform needed initialization for the new class.
To handle Windows notification messages sent from a CEdit object to its parent, add the following message-map entries to the parent class message map:
ON_COMMAND
ON_EN_SETFOCUS
ON_EN_KILLFOCUS
ON_EN_MAXTEXT
ON_EN_CHANGE
ON_EN_UPDATE
ON_EN_HSCROLL
ON_EN_VSCROLL
Apply the following window styles to an edit control:
Style | Application |
WS_CHILD | Always. |
WS_VISIBLE | Usually. |
WS_DIABLED | Rarely. |
WS_GROUP | To group controls. |
WS_TABSTOP | To include edit control in the tabbing order. |
See CreateEx in the CWnd base class for a full description of these window styles.
Use any combination of the following edit control styles for dwStyle:
Style | Meaning |
ES_AUTOHSCROLL | Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line. When the user presses the ENTER key, the control scrolls all text back to position 0. |
ES_AUTOVSCROLL | Automatically scrolls text up one page when the user presses ENTER on the last line. |
ES_CENTER | Centers text in a multiline edit control. |
ES_LEFT | Aligns text flush-left. |
ES_LOWERCASE | Converts all characters to lowercase as they are typed into the edit control. |
ES_MULTILINE | Designates a multiple-line edit control. (The default is single-line.) If the ES_AUTOVSCROLL style is specified, the edit control shows as many lines as possible and scrolls vertically when the user presses the ENTER key. If ES_AUTOVSCROLL is not given, the edit control shows as many lines as possible and beeps if ENTER is pressed when no more lines can be displayed. |
If the ES_AUTOHSCROLL style is specified, the multiple-line edit control automatically scrolls horizontally when the caret goes past the right edge of the control. To start a new line, the user must press ENTER. If ES_AUTOHSCROLL is not given, the control automatically wraps words to the beginning of the next line when necessary; a new line is also started if ENTER is pressed. The position of the wordwrap is determined by the window size. If the window size changes, the wordwrap position changes, and the text is redisplayed. | |
Multiple-line edit controls can have scroll bars. An edit control with scroll bars processes its own scroll-bar messages. Edit controls without scroll bars scroll as described above, and process any scroll messages sent by the parent window. | |
ES_NOHIDESEL | Normally, an edit control hides the selection when the control loses the input focus, and inverts the selection when the control receives the input focus. Specifying ES_NOHIDESEL deletes this default action. |
ES_OEMCONVERT | Text entered in the edit control is converted from the ANSI character set to the OEM character set and then back to ANSI. This ensures proper character conversion when the application calls the AnsiToOem Windows function to convert an ANSI string in the edit control to OEM characters. This style is most useful for edit controls that contain filenames. |
ES_PASSWORD | Displays all characters as an asterisk (*) as they are typed into the edit control. An application can use the SetPasswordChar member function to change the character that is displayed. |
ES_RIGHT | Aligns text flush-right in a multiline edit control. |
ES_UPPERCASE | Converts all characters to uppercase as they are typed into the edit control. |
Create returns TRUE if initialization is successful; FALSE if unsuccessful.