Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 2 Variables and Identifiers Visual C++ and MFC Fundamentals


"If you think there is a mistake, please contact HR.\n"
"You can also send an email to [email protected]");

return TRUE;
}


  1. Test the application


Figure 39: Creating a Multiline Message Box...........................................................................



  1. Click OK to close the message box and return to MSVC.


2.3.5 The Message’ Title.................................................................................


The caption of the message box is the text that displays on its title bar. If you create a
message box using the CWnd::MessageBox() method or the AfxMessageBox()
function, which allow you to specify only one argument, namely the text to display to the
user, which is the value of the Text argument, the title bar of the message box would
display the name of the application that "owns" the message box. If you want to display a
more meaningful title, specify the second argument.

The Caption argument is a null-terminated string that would display on the title bar of the
message box. Here is an example:

void CDialog1Dlg::OnBnClickedBtnMsg1()
{
// TODO: Add your control notification handler code here
MessageBox("Due to an unknown internal error, this application will now close.",
"Regular Warning");
}

Although the Caption argument is optional for the CWnd::MessageBox() method and
the AfxMessageBox() function, it is required for the Win32’s MessageBox() function.
Because it is in fact a pointer, you can pass it as NULL. In this case, the title bar of the
message box would display Error. This caption may not be friendly on most application
and could appear freightening to the user. Therefore, unless you are in a hurry, you
should strive to provide a friendly and more appropriate title.

Practical Learning: Displaying a Message’s Caption



  1. To display a caption for the message box, change the MessageBox() call as follows:


BOOL CExerciseApp::InitInstance()
{
CWnd *Msg = new CWnd;
Msg->MessageBox("The name you entered is not in our records.\n"
"If you think there is a mistake, please contact HR.\n"
"You can also send an email to [email protected]",
Free download pdf