An Edit Box is a rectangular child window in which the user can enter text. It is represented by CEdit class.
Sr.No.
Name & Description
1
CanUndo
Determines whether an edit-control operation can be undone.
2
CharFromPos
Retrieves the line and character indexes for the character closest to a specified position.
3
Clear
Deletes (clears) the current selection (if any) in the edit control.
4
Copy
Copies the current selection (if any) in the edit control to the Clipboard in CF_TEXT format.
5
Create
Creates the Windows edit control and attaches it to the CEdit object.
6
Cut
Deletes (cuts) the current selection (if any) in the edit control and copies the deleted text to the Clipboard in CF_TEXT format.
7
EmptyUndoBuffer
Resets (clears) the undo flag of an edit control.
8
FmtLines
Sets the inclusion of soft line-break characters on or off within a multiple-line edit control.
9
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.
10
GetFirstVisibleLine
Determines the topmost visible line in an edit control.
11
GetHandle
Retrieves a handle to the memory that is currently allocated for a multiple-line edit control.
12
GetHighlight
Gets the indexes of the starting and ending characters in a range of text that is highlighted in the current edit control.
13
GetLimitText
Gets the maximum amount of text this CEdit can contain.
14
GetLine
Retrieves a line of text from an edit control.
15
GetLineCount
Retrieves the number of lines in a multipleline edit control.
16
GetMargins
Gets the left and right margins for this CEdit.
17
GetModify
Determines whether the contents of an edit control have been modified.
18
GetPasswordChar
Retrieves the password character displayed in an edit control when the user enters text.
19
GetRect
Gets the formatting rectangle of an edit control.
20
GetSel
Gets the first and last character positions of the current selection in an edit control.
21
HideBalloonTip
Hides any balloon tip associated with the current edit control.
22
LimitText
Limits the length of the text that the user can enter into an edit control.
23
LineFromChar
Retrieves the line number of the line that contains the specified character index.
24
LineIndex
Retrieves the character index of a line within a multiple-line edit control.
25
LineLength
Retrieves the length of a line in an edit control.
26
LineScroll
Scrolls the text of a multiple-line edit control.
27
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.
28
PosFromChar
Retrieves the coordinates of the upper-left corner of a specified character index.
29
ReplaceSel
Replaces the current selection in an edit control with the specified text.
30
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.
31
SetHandle
Sets the handle to the local memory that will be used by a multiple-line edit control.
32
SetHighlight
Highlights a range of text that is displayed in the current edit control.
33
SetLimitText
Sets the maximum amount of text this CEdit can contain.
34
SetMargins
Sets the left and right margins for this CEdit.
35
SetModify
Sets or clears the modification flag for an edit control.
36
SetPasswordChar
Sets or removes a password character displayed in an edit control when the user enters text.
37
SetReadOnly
Sets the read-only state of an edit control.
38
SetRect
Sets the formatting rectangle of a multipleline edit control and updates the control.
39
SetRectNP
Sets the formatting rectangle of a multipleline edit control without redrawing the control window.
40
SetSel
Selects a range of characters in an edit control.
41
SetTabStops
Sets the tab stops in a multiple-line edit control.
42
ShowBalloonTip
Displays a balloon tip that is associated with the current edit control.
43
Undo
Reverses the last edit-control operation.
Message
Map entry
Description
EN_CHANGE
ON_EN_CHANGE( <id>, <memberFxn> )
The user has taken an action that may have altered text in an edit control.
EN_ERRSPACE
ON_EN_ERRSPACE( <id>, <memberFxn> )
The edit control cannot allocate enough memory to meet a specific request.
EN_HSCROLL
ON_EN_HSCROLL( <id>, <memberFxn> )
The user clicks an edit control's horizontal scroll bar. The parent window is notified before the screen is updated.
EN_KILLFOCUS
ON_EN_KILLFOCUS( <id>, <memberFxn> )
The edit control loses the input focus.
MAXTEXT
ON_MAXTEXT( <id>, <memberFxn> )
The current insertion has exceeded the specified number of characters for the edit control and has been truncated.
EN_SETFOCUS
ON_EN_SETFOCUS( <id>, <memberFxn> )
Sent when an edit control receives the input focus.
EN_UPDATE
ON_EN_UPDATE( <id>, <memberFxn> )
he 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.
EN_VSCROLL
ON_EN_VSCROLL( <id>, <memberFxn> )
The user clicks an edit control's vertical scroll bar. The parent window is notified before the screen is updated.
Let us into a simple example by creating a new MFC dialog based project.
Step 1 − Remove the caption of Static Text control and drag one button and one Edit control.
Step 2 − Add a control variable m_editCtrl for edit control and value variable m_strTextCtrl for Static text control.
Step 3 − Add the event handler for button click event.
Step 4 − Here is the implementation of event handler for button click event.
void CMFCEditDlg::OnBnClickedButton1() {
// TODO: Add your control notification handler code here
CString str = _T("");
m_editCtrl.GetWindowTextW(str);
if (!str.IsEmpty())
m_strTextCtrl = str;
else
m_strTextCtrl = _T("Write Something");
UpdateData(FALSE);
}
Step 5 − When the above code is compiled and executed, you will see the following.
Step 6 − When you write text in the edit control and click Display, it will update that text on Static Text Control.