Description
An edit control is a rectangular control window typically used in a dialog
box to permit the user to enter and edit text by typing on the keyboard.Edit
controls are typically used in dialog boxes, but you can use them in the client
area of a standard window as well. Single-line edit controls are useful for
retrieving a single string from the user. Multiline edit controls make it easy
for your application to implement most of the features of a simple word
processor.
Refer to the documentation that ships with the Microsoft Windows Software
Development Kit for more information on the use of edit controls.
CEdit Members
Construction
CEdit |
CEdit();
Constructor for CEdit. |
Attributes
GetFirstVisibleLine |
int GetFirstVisibleLine() const;
Returns the zero-based index of the first
visible character in a single-line edit control or the zero-based index of
the uppermost visible line in a multiline edit control. |
GetHandle |
HLOCAL GetHandle() const;
Returns a handle identifying the buffer
containing the multiline edit control's text. It is not processed by
single-line edit controls. |
GetLimitText |
UINT GetLimitText() const;
Returns the current text limit, in
characters. |
GetLine |
int GetLine(int nIndex, LPTSTR lpszBuffer) const;
int GetLine(int nIndex, LPTSTR lpszBuffer, int nMaxLength) const;
Copies characters in a single-line edit
control to a buffer and returns the number of characters copied. In a
multiline edit control, retrieves a line of text from the control and
returns the number of characters copied. |
GetLineCount |
int GetLineCount() const;
Returns the number of lines in the edit
control. |
GetMargins |
DWORD GetMargins() const;
Returns the widths of the left and right
margins. |
GetModify |
BOOL GetModify() const;
Returns a flag indicating whether the content
of an edit control has been modified. |
GetPasswordChar |
TCHAR GetPasswordChar() const;
Returns the character that edit controls use
in conjunction with the ES_PASSWORD style. |
GetRect |
void GetRect(LPRECT lpRect) const;
Returns the coordinates of the formatting
rectangle in an edit control. |
GetSel |
void GetSel(int& nStartChar, int& nEndChar) const;
Returns the starting and ending character
positions of the current selection in the edit control. |
SetHandle |
void SetHandle(HLOCAL hBuffer) const;
Sets a handle to the memory used as a text
buffer, empties the undo buffer, resets the scroll positions to zero, and
redraws the window. |
SetLimitText |
void SetLimitText(UINT nMax) const;
Sets the maximum number of characters the user
may enter in the edit control. |
SetMargins |
void SetMargins(UINT nLeft, UINT nRight) const;
Sets the widths of the left and right
margins, and redraws the edit control to reflect the new margins. |
SetModify |
void SetModify(BOOL bModified = TRUE) const;
Sets or clears the modification flag to
indicate whether the edit control has been modified. |
SetPasswordChar |
void SetPasswordChar(TCHAR ch) const;
Defines the character that edit controls use
in conjunction with the ES_PASSWORD style. |
SetReadOnly |
BOOL SetReadOnly(BOOL bReadOnly = TRUE) const;
Sets or removes the read-only style (ES_READONLY)
in an edit control. |
SetRect |
void SetRect(LPCRECT lpRect) const;
Sets the formatting rectangle for the
multiline edit control and redraws the window. It is not processed by
single-line edit controls. |
SetRectNP |
void SetRectNP(LPCRECT lpRect) const;
Sets the formatting rectangle for the
multiline edit control but does not redraw the window. It is not processed
by single-line edit controls. |
SetSel |
void SetSel(DWORD dwSelection, BOOL bNoScroll) const;
void SetSel(int nStartChar, int nEndChar, BOOL bNoScroll) const;
Selects a range of characters in the edit
control by setting the starting and ending positions to be selected. |
SetTabStops |
BOOL SetTabStops(int nTabStops, LPINT rgTabStops) const;
BOOL SetTabStops(const int& cxEachStop) const;
BOOL SetTabStops() const;
Sets tab-stop positions in the multiline edit
control. It is not processed by single-line edit controls. |
Operations
CanUndo |
BOOL CanUndo() const;
Returns TRUE if the edit control operation
can be undone. |
CharFromPos |
int CharFromPos(CPoint pt) const;
Returns the character index and line index of
the character nearest the specified point. |
Clear |
void Clear() const;
Clears the current selection, if any, in an
edit control. If there is no current selection, deletes the character to the
right of the caret. |
Copy |
void Copy() const;
Copies text to the clipboard unless the style
is ES_PASSWORD, in which case the message returns zero. |
Cut |
void Cut() const;
Cuts the selection to the clipboard, or
deletes the character to the left of the cursor if there is no selection. |
EmptyUndoBuffer |
void EmptyUndoBuffer() const;
Empties the undo buffer and sets the undo
flag retrieved by the EM_CANUNDO message to FALSE. The system automatically
clears the undo flag whenever the edit control receives a WM_SETTEXT or
EM_SETHANDLE message. |
FmtLines |
BOOL FmtLines(BOOL bAddEOL) const;
Adds or removes soft line-break characters
(two carriage returns and a line feed) to the ends of wrapped lines in a
multiline edit control. It is not processed by single-line edit controls. |
LimitText |
void LimitText(int nChars = 0) const;
Sets the text limit of an edit control. The
text limit is the maximum amount of text, in TCHARs, that the user can type
into the edit control. |
LineFromChar |
int LineFromChar(int nIndex = -1) const;
Returns the zero-based number of the line in
a multiline edit control that contains a specified character index. This
message is the reverse of the EM_LINEINDEX message. It is not processed by
single-line edit controls. |
LineIndex |
int LineIndex(int nLine = -1) const;
Returns the character of a line in a
multiline edit control. This message is the reverse of the EM_LINEFROMCHAR
message. It is not processed by single-line edit controls. |
LineLength |
int LineLength(int nLine = -1) const;
Returns the length, in characters, of a
single-line edit control. In a multiline edit control, returns the length,
in characters, of a specified line. |
LineScroll |
void LineScroll(int nLines, int nChars = 0) const;
Scrolls the text vertically in a single-line
edit control or horizontally in a multiline edit control (when the control
has the ES_LEFT style). The lParam parameter specifies the number of lines
to scroll vertically, starting from the current line. The wParam parameter
specifies the number of characters to scroll horizontally, starting from the
current character. |
Paste |
void Paste() const;
Pastes text from the clipboard into the edit
control window at the caret position. |
PosFromChar |
CPoint PosFromChar(UINT nChar) const;
Returns the client coordinates of the
specified character. |
ReplaceSel |
void ReplaceSel(LPCTSTR lpszNewText, BOOL bCanUndo) const;
Replaces the current selection with the text
in an application-supplied buffer, sends the parent window EN_UPDATE and
EN_CHANGE messages, and updates the undo buffer. |
Undo |
void Undo() const;
Removes any text that was just inserted or
inserts any deleted characters and sets the selection to the inserted text.
If necessary, sends the EN_UPDATE and EN_CHANGE notification messages to the
parent window. |
Overidables
PreRegisterClass |
virtual void PreRegisterClass(WNDCLASS &wc);
Set the window class parameters before the window is created. |
Base class Members
For base class members, refer to the members of CWnd.
Remarks
Like all common controls, the edit control requires a parent window. This
parent window is often a dialog, but
simple windows can also be the parent
window for an edit control.
Summary Information
Header file |
stdcontrols.h |
Win32/64 support |
Yes |
WinCE support |
Yes |
Library required |
Comctl32.lib |