Visual C++ and MFC Fundamentals Chapter 2: Introduction to MFC
Figure 37: A Simple Message Box with MessageBox()..........................................................
If you want to display the message on various lines, you can separate sections with the
new line character '\n'. Here is an example:
void Whatever()
{
// TODO: Add your control notification handler code here
MessageBox("If you think there is a mistake,\nplease contact HR");
}
Figure 38: A Message's Box on Various Lines.........................................................................
If the message you are creating is too long to fit on one line, you can separate lines by
ending each with a double-quote and starting the next line with a new qouble-quote. As
long as you have not closed the function, the string would be considered as one entity.
You can also use string editing and formatting techniques to create a more elaborate
message. This means that you can use functions of the C string library to create your
message.
Practical Learning: Displaying a Message
- To prepare a message for the user, in the InitInstance() member function, call the
AfxMessageBox() function as follows:
#include <afxwin.h>
class CExerciseApp : public CWinApp
{
public:
BOOL InitInstance();
};
CExerciseApp theApp;
BOOL CExerciseApp::InitInstance()
{
CWnd *Msg = new CWnd;
Msg->MessageBox("The name you entered is not in our records.\n"