Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 2: Introduction to MFC


Practical Learning: Using a Message Box



  1. To display an combination of buttons on the message box, change the InitInstance()
    member function as follows:


BOOL CExerciseApp::InitInstance()
{
::MessageBox(NULL,
"The username you entered is not in our records.\n"
"Do you wish to contact Human Resources?",
"Failed Logon Attempt",
MB_YESNO);

return TRUE;
}


  1. Test the application


Figure 42: Creating a Message Box............................................................................................



  1. Close it and return to MSVC

  2. To display the message box with an icon, change InitInstance() as follows:


BOOL CExerciseApp::InitInstance()
{
CWnd *Msg = new CWnd;

Msg->MessageBox("The credentials you entered are not in our records.\n"
"What do you want to do? Click:\n"
"Yes\tto contact Human Resources\n"
"No\tto close the application\n"
"Cancel\tto try again\n",
"Failed Logon Attempt",
MB_YESNOCANCEL | MB_ICONQUESTION);

return TRUE;
}


  1. Test the application

Free download pdf