Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


void CExerciseView::OnBnClickedBtnAccount()
{
// TODO: Add your control notification handler code here
// Take over from the application
UpdateData();

// Get the full name by appending the last name to the first
CString FullName = m_StrFirstName + " " + m_StrLastName;
// Create a temporary username made of the
// first letter of the first name + the last name
CString TempUsername = m_StrFirstName.Left(1) + m_StrLastName;
// Make an attempt to create a username made of 5 letters
CString SuggestedUsername = TempUsername.Left(5);

// What if the attempted username is less than 5 characters
if( TempUsername.GetLength() < 5 )
{
// Since the username is < 5 characters,
// add some digits to make it valid
SuggestedUsername = TempUsername + "1234";
// now that we have a username with at least 5 letters,
// Retrieve only the first 5 to create a new username
SuggestedUsername = SuggestedUsername.Left(5);
}

// It is time to access the Employee Account Setup dialog box
CAccountDlg Dlg;

// Transfer the the full name to the Employee Account Setup dialog box
Dlg.m_StrFullName.Format("%s", FullName);
Dlg.m_StrUsername.Format("%s", SuggestedUsername);

// Display the Employee Account Setup dialog box
Dlg.DoModal();

// Hand the operations back to the application
UpdateData(FALSE);
}


  1. On top of the current source file, include the AccountDlg.h header file


#include "stdafx.h"
#include "Clarksville Ice Scream1.h"

#include "ExerciseDoc.h"
#include "ExerciseView.h"
#include "AccountDlg.h"


  1. Test the application and return to MSVC

  2. Open the Geometry application. If you do not have it, open one the Geometry4
    application that accompanies this book.

  3. Open each IDD_CIRCULAR dialog

  4. Click the top Radius edit box. Press and hold Ctrl. Then click each one of the other
    boxes to select them. Then release Ctrl

  5. On the Properties window, set the Align Text property to Right

  6. In the same way, set the Align Text property of the edit boxes of the IDD_G3D and
    the IDD_QUADRILATERAL dialog boxes to Right

Free download pdf