Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 16: Text-Based Controls Visual C++ and MFC Fundamentals


// TODO: Add your control notification handler code here
m_FirstName.GetWindowText(m_strFirstName);
m_LastName.GetWindowText(m_strLastName);
CString FullName = m_strFirstName + " " + m_strLastName;

m_FullName.SetWindowText(FullName);
}

ON_EN_UPDATE: The OnUpdate() event is sent after the content of an edit box has
changed but before the text is formally displayed.

ON_EN_MAXTTEXT: When adding a variable for the edit control, you can specify the
maximum allowable number of characters the user can enter. If the user attempts
exceeding this maximum, an OnMaxtext() event is sent. You can catch this event to let
the user know about the problem. If you set up the Maximum Characters fine, you do not
need to perform any "if" or "while" checking. The edit control would do it itself.

ON_EN_ERRSPACE: The OnErrSpace() event is event is sent if the compiler
encountered a problem when attempting to allocate memory space to the control.

ON_EN_KILLFOCUS: The OnExit() event occurs when the control loses focus. In the
case of an edit box, this could happen if the control has focus and the user presses Tab;
the edit box would lose focus.

Practical Learning: Using Edit Box Notifications



  1. The Clarksville Ice Scream1 application should still be opened
    Display the Employee Account Setup dialog box

  2. If you are using MSVC 6, display the Message Maps property page of the
    ClassWizard dialog box. Then click IDC_USERNAME
    If you are using MSVC 7, right-click the Suggested Username edit box and click
    Add Event Handler

  3. Add an event handler for the EN_MAXTEXT message and click either Edit Code or
    Finish

  4. Implement the event as follows:


void CAccountDlg::OnEnMaxtextUsername()
{
// TODO: Add your control notification handler code here
MessageBox("A username must have a maximum of 5 characters");
}
Free download pdf