Partager via


CEdit Class

Provides the functionality of a Windows edit control.

class CEdit : public CWnd

Members

Public Constructors

Name

Description

CEdit::CEdit

Constructs a CEdit control object.

Public Methods

Name

Description

CEdit::CanUndo

Determines whether an edit-control operation can be undone.

CEdit::CharFromPos

Retrieves the line and character indexes for the character closest to a specified position.

CEdit::Clear

Deletes (clears) the current selection (if any) in the edit control.

CEdit::Copy

Copies the current selection (if any) in the edit control to the Clipboard in CF_TEXT format.

CEdit::Create

Creates the Windows edit control and attaches it to the CEdit object.

CEdit::Cut

Deletes (cuts) the current selection (if any) in the edit control and copies the deleted text to the Clipboard in CF_TEXT format.

CEdit::EmptyUndoBuffer

Resets (clears) the undo flag of an edit control.

CEdit::FmtLines

Sets the inclusion of soft line-break characters on or off within a multiple-line edit control.

CEdit::GetCueBanner

Retrieves the text that is displayed as the text cue, or tip, in an edit control when the control is empty and does not have focus.

CEdit::GetFirstVisibleLine

Determines the topmost visible line in an edit control.

CEdit::GetHandle

Retrieves a handle to the memory that is currently allocated for a multiple-line edit control.

CEdit::GetHighlight

Gets the indexes of the starting and ending characters in a range of text that is highlighted in the current edit control.

CEdit::GetLimitText

Gets the maximum amount of text this CEdit can contain.

CEdit::GetLine

Retrieves a line of text from an edit control.

CEdit::GetLineCount

Retrieves the number of lines in a multiple-line edit control.

CEdit::GetMargins

Gets the left and right margins for this CEdit.

CEdit::GetModify

Determines whether the contents of an edit control have been modified.

CEdit::GetPasswordChar

Retrieves the password character displayed in an edit control when the user enters text.

CEdit::GetRect

Gets the formatting rectangle of an edit control.

CEdit::GetSel

Gets the first and last character positions of the current selection in an edit control.

CEdit::HideBalloonTip

Hides any balloon tip associated with the current edit control.

CEdit::LimitText

Limits the length of the text that the user can enter into an edit control.

CEdit::LineFromChar

Retrieves the line number of the line that contains the specified character index.

CEdit::LineIndex

Retrieves the character index of a line within a multiple-line edit control.

CEdit::LineLength

Retrieves the length of a line in an edit control.

CEdit::LineScroll

Scrolls the text of a multiple-line edit control.

CEdit::Paste

Inserts the data from the Clipboard into the edit control at the current cursor position. Data is inserted only if the Clipboard contains data in CF_TEXT format.

CEdit::PosFromChar

Retrieves the coordinates of the upper-left corner of a specified character index.

CEdit::ReplaceSel

Replaces the current selection in an edit control with the specified text.

CEdit::SetCueBanner

Sets the text that is displayed as the text cue, or tip, in an edit control when the control is empty and does not have focus.

CEdit::SetHandle

Sets the handle to the local memory that will be used by a multiple-line edit control.

CEdit::SetHighlight

Highlights a range of text that is displayed in the current edit control.

CEdit::SetLimitText

Sets the maximum amount of text this CEdit can contain.

CEdit::SetMargins

Sets the left and right margins for this CEdit.

CEdit::SetModify

Sets or clears the modification flag for an edit control.

CEdit::SetPasswordChar

Sets or removes a password character displayed in an edit control when the user enters text.

CEdit::SetReadOnly

Sets the read-only state of an edit control.

CEdit::SetRect

Sets the formatting rectangle of a multiple-line edit control and updates the control.

CEdit::SetRectNP

Sets the formatting rectangle of a multiple-line edit control without redrawing the control window.

CEdit::SetSel

Selects a range of characters in an edit control.

CEdit::SetTabStops

Sets the tab stops in a multiple-line edit control.

CEdit::ShowBalloonTip

Displays a balloon tip that is associated with the current edit control.

CEdit::Undo

Reverses the last edit-control operation.

Remarks

An edit control is a rectangular child window in which the user can enter text.

You can create an edit control either from a dialog template or directly in your code. In both cases, first call the constructor CEdit to construct the CEdit object, then call the Create member function to create the Windows edit control and attach it to the CEdit object.

Construction can be a one-step process in a class derived from CEdit. Write a constructor for the derived class and call Create from within the constructor.

CEdit inherits significant functionality from CWnd. To set and retrieve text from a CEdit object, use the CWnd member functions SetWindowText and GetWindowText, which set or get the entire contents of an edit control, even if it is a multiline control. Text lines in a multiline control are separated by '\r\n' character sequences. Also, if an edit control is multiline, get and set part of the control's text by calling the CEdit member functions GetLine, SetSel, GetSel, and ReplaceSel.

If you want to handle Windows notification messages sent by an edit control to its parent (usually a class derived from CDialog), add a message-map entry and message-handler member function to the parent class for each message.

Each message-map entry takes the following form:

ON_Notification( id, memberFxn )

where id specifies the child window ID of the edit control sending the notification, and memberFxn is the name of the parent member function you have written to handle the notification.

The parent's function prototype is as follows:

afx_msg void memberFxn**( );**

Following is a list of potential message-map entries and a description of the cases in which they would be sent to the parent:

  • ON_EN_CHANGE   The user has taken an action that may have altered text in an edit control. Unlike the EN_UPDATE notification message, this notification message is sent after Windows updates the display.

  • ON_EN_ERRSPACE   The edit control cannot allocate enough memory to meet a specific request.

  • ON_EN_HSCROLL   The user clicks an edit control's horizontal scroll bar. The parent window is notified before the screen is updated.

  • ON_EN_KILLFOCUS   The edit control loses the input focus.

  • ON_EN_MAXTEXT   The current insertion has exceeded the specified number of characters for the edit control and has been truncated. Also sent when an edit control does not have the ES_AUTOHSCROLL style and the number of characters to be inserted would exceed the width of the edit control. Also sent when an edit control does not have the ES_AUTOVSCROLL style and the total number of lines resulting from a text insertion would exceed the height of the edit control.

  • ON_EN_SETFOCUS   Sent when an edit control receives the input focus.

  • ON_EN_UPDATE   The edit control is about to display altered text. Sent after the control has formatted the text but before it screens the text so that the window size can be altered, if necessary.

  • ON_EN_VSCROLL   The user clicks an edit control's vertical scroll bar. The parent window is notified before the screen is updated.

If you create a CEdit object within a dialog box, the CEdit object is automatically destroyed when the user closes the dialog box.

If you create a CEdit object from a dialog resource using the dialog editor, the CEdit object is automatically destroyed when the user closes the dialog box.

If you create a CEdit object within a window, you may also need to destroy it. If you create the CEdit object on the stack, it is destroyed automatically. If you create the CEdit object on the heap by using the new function, you must call delete on the object to destroy it when the user terminates the Windows edit control. If you allocate any memory in the CEdit object, override the CEdit destructor to dispose of the allocations.

To modify certain styles in an edit control (such as ES_READONLY) you must send specific messages to the control instead of using ModifyStyle. See Edit Control Styles in the Windows SDK.

For more information on CEdit, see:

  • Controls

  • Knowledge Base article Q259949 : INFO: SetCaretPos() Is Not Appropriate with CEdit or CRichEditCtrl Controls

Inheritance Hierarchy

CObject

CCmdTarget

CWnd

CEdit

Requirements

Header: afxwin.h

See Also

Reference

CWnd Class

Hierarchy Chart

CWnd Class

CButton Class

CComboBox Class

CListBox Class

CScrollBar Class

CStatic Class

CDialog Class

Concepts

MFC Sample CALCDRIV

MFC Sample CMNCTRL2