CWnd::MessageBox

创建并显示包含一个由应用程序提供的消息和说明的窗口,以及预定义的图标的组合,并在 消息框样式 描述的普通按钮列表。

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

参数

  • lpszText
    指向 CString 包含消息的对象或Null终止的字符串将显示。

  • lpszCaption
    指向 CString 为消息框中声明或Null终止的字符串将使用的对象。 如果 lpszCaption 是 NULL,则使用默认声明为“false”。

  • nType
    指定消息框的内容和行为。

返回值

此方法使用 MessageBox 功能(如中所 Windows SDK定义。 此方法调用返回此函数的结果。

备注

使用全局函数 AfxMessageBox 而不是该成员函数的实现在应用程序的消息框。

下面演示可用于消息框的不同系统图标:

StopSymbol 屏幕快照

MB_ICONHANDMB_ICONSTOPMB_ICONERROR

QuestionWordBubbleSymbol 屏幕快照

MB_ICONQUESTION

ExclamationSymbol 屏幕快照

MB_ICONEXCLAMATIONMB_ICONWARNING

InformationSymbol 屏幕快照

MB_ICONASTERISKMB_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

请参见

参考

CWnd 类

层次结构图

MessageBox

AfxMessageBox