int MessageBox(hWndParent,lpText,lpCaption,wType)
This function creates and displays a window that contains an application-supplied message and caption, plus any combination of the predefined icons and push buttons described in the following list.
Parameter | Type/Description |
hWndParent | HWND Identifies the window that owns the message box. | |
lpText | LPSTR Points to a null-terminated string containing the message to be displayed. | |
lpCaption | LPSTR Points to a null-terminated character string to be used for the dialog-box caption. If the lpCaption parameter is NULL, the default caption “Error” is used. | |
wType | WORD Specifies the contents of the dialog box. It can be any combination of the values shown in Table R.11, “Message Box Types,” joined by the bitwise OR operator. |
The return value specifies the outcome of the function. It is zero if there is not enough memory to create the message box. Otherwise, it is one of the following menu-item values returned by the dialog box:
Value | Meaning |
IDABORT | Abort button pressed. | |
IDCANCEL | Cancel button pressed. | |
IDIGNORE | Ignore button pressed. | |
IDNO | No button pressed. | |
IDOK | OK button pressed. | |
IDRETRY | Retry button pressed. | |
IDYES | Yes button pressed. |
If a message box has a Cancel button, the IDCANCEL value will be returned if either the ESCAPE key or Cancel button is pressed. If the message box has no Cancel button, pressing the ESCAPE key has no effect.
When a system-modal message box is created to indicate that the system is low on memory, the strings passed as the lpText and lpCaption parameters should not be taken from a resource file, since an attempt to load the resource may fail.
When an application calls the MessageBox function and specifies the MB_ICONHAND and MB_SYSTEMMODAL flags for the wType parameter, Windows will display the resulting message box regardless of available memory. When these flags are specified, Windows limits the length of the message-box text to one line.
If a message box is created while a dialog box is present, use the handle of the dialog box as the hWndParent parameter. The hWndParent parameter should not identify a child window, such as a dialog-box control.
Table R.11 shows the message box types.
Table R.11 Message Box Types
Value | Meaning |
MB_ABORTRETRYIGNORE | Message box contains three push buttons: Abort, Retry, and Ignore. |
MB_APPLMODAL | The user must respond to the message box before continuing work in the window identified by the hWndParent parameter. However, the user can move to the windows of other applications and work in those windows. MB_APPLMODAL is the default if neither MB_SYSTEMMODAL nor MB_TASKMODAL are specified. |
MB_DEFBUTTON1 | First button is the default. Note that the first button is always the default unless MB_DEFBUTTON2 or MB_DEFBUTTON3 is specified. |
MB_DEFBUTTON2 | Second button is the default. |
MB_DEFBUTTON3 | Third button is the default. |
MB_ICONASTERISK | Same as MB_ICONINFORMATION. |
MB_ICONEXCLAMATION | An exclamation-point icon appears in the message box. |
MB_ICONHAND | Same as MB_ICONSTOP. |
MB_ICONINFORMATION | An icon consisting of a lowercase i in a circle appears in the message box. |
MB_ICONQUESTION | A question-mark icon appears in the message box. |
MB_ICONSTOP | A stop sign icon appears in the message box. |
MB_OK | Message box contains one push button: OK. |
MB_OKCANCEL | Message box contains two push buttons: OK and Cancel. |
Table R.11 Message Box Types (continued)
Value | Meaning |
MB_RETRYCANCEL | Message box contains two push buttons: Retry and Cancel. |
MB_SYSTEMMODAL | All applications are suspended until the user responds to the message box. Unless the application specifies MB_ICONHAND, the message box does not become modal until after it is created; consequently, the parent window and other windows continue to receive messages resulting from its activation. System-modal message boxes are used to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). |
MB_TASKMODAL | Same as MB_APPMODAL except that all the top-level windows belonging to the current task are disabled if the hWndOwner parameter is NULL. This flag should be used when the calling application or library does not have a window handle available, but still needs to prevent input to other windows in the current application without suspending other applications. |
MB_YESNO | Message box contains two push buttons: Yes and No. |
MB_YESNOCANCEL | Message box contains three push buttons: Yes, No, and Cancel. |