Visual C++ and MFC Fundamentals Chapter 17: Track-Based Controls
- Add an event handler to the Validate button and implement it as follows:
void CAccountDlg::OnBnClickedBtnValidate()
{
// TODO: Add your control notification handler code here
UpdateData();
// In case the user decided to change the username,
// make sure the username is = 5 characters
if( m_StrUsername.GetLength() == 5 )
{
// Since the username is 5 characters, check the password
if( m_StrPassword.GetLength() == 0 )
{
MessageBox("Blank passwords are not allowed");
m_Password.SetFocus();
}
else if( m_StrPassword == m_StrConfPassword )
MessageBox("The account is ready\n"
"To create the account, click OK.\n"
"To stop the account processing, click Cancel.");
else // if( m_StrPassword != m_StrConfPassword )
{
MessageBox("The passwords do not match");
m_Password.SetWindowText("");
m_Password.SetFocus();
}
}
// Since the username specified less than 3 characters, display a message
accordingly
// Set the focus to the Username edit box
else
{
MessageBox("A username must have 5 characters");
m_Username.SetFocus();
}
UpdateData(FALSE);
}
- Display the main form
- Set the Disabled property of the Account Setup button to True
- As done for the EN_MAXTEXT, add an EN_UPDATE event handler to the First
Name edit box - Also add an EN_UPDATE event handler to the Last Name edit box
- Implement both events as follows:
void CExerciseView::OnUpdateFirstName()
{
// TODO: Add your control notification handler code here
// Let the edit boxes take over
UpdateData();
// Make sure both the First Name and the Last Name edit boxes are not empty
// If one of them is, the account cannot be created.
// In which case, disable the the Account Setup button
if( (m_FirstName.GetLength() == 0) || (m_LastName.GetLength() == 0) )
m_BtnAccount.EnableWindow(FALSE);