Export (0) Print
Expand All
MFC
Expand Minimize

CWnd::MessageBox

Creates and displays a window that contains an application-supplied message and caption, plus a combination of the predefined icons and pushbuttons described in the Message-Box Styles list.

int MessageBox(
   LPCTSTR lpszText,
   LPCTSTR lpszCaption = NULL,
   UINT nType = MB_OK 
);

lpszText

Points to a CString object or null-terminated string containing the message to be displayed.

lpszCaption

Points to a CString object or null-terminated string to be used for the message-box caption. If lpszCaption is NULL, the default caption "Error" is used.

nType

Specifies the contents and behavior of the message box.

This method utilizes the MessageBox function as defined in the Windows SDK. This method returns the result of calling this function.

Use the global function AfxMessageBox instead of this member function to implement a message box in your application.

The following shows the various system icons that can be used in a message box:

StopSymbol screenshot

MB_ICONHAND, MB_ICONSTOP, and MB_ICONERROR

QuestionWordBubbleSymbol screenshot

MB_ICONQUESTION

ExclamationSymbol screenshot

MB_ICONEXCLAMATION and MB_ICONWARNING

InformationSymbol screenshot

MB_ICONASTERISK and MB_ICONINFORMATION


void CMainFrame::OnDisplayErrorMessage()
{
   // This displays a message box with the title "Error"
   // and the message "Help, Something went wrong."
   // The error icon is displayed in the message box, along with
   // an OK button.
   MessageBox(_T("Help, Something went wrong."), _T("Error"), 
      MB_ICONERROR | MB_OK);
}


Header: afxwin.h

Community Additions

ADD
Show:
© 2014 Microsoft