Synopsis
int MessageBox(
HWND hWnd, // Handle to the window to display the message box.
LPCTSTR lpText, // The text to display in the message box.
HWND hIcon, // Optional. An icon to display in the message box.
INT_PTR uType // Flags that control the appearance and behavior of the message box.
);
Parameters
hWnd
HWND
The handle of the window to display the message box. If hWnd is NULL, the message box is displayed in the first active window.
lpText
LPCTSTR
A C-style string literal that specifies the text to display in the message box.
hIcon
HWND
An optional icon to display in the message box.
uType
INT_PTR
Flags that control the appearance and behavior of the message box. These flags are defined in MessageBoxFunction. The following flags are available:
- MB_OK: Displays an OK button.
- MB_CANCEL: Displays an OK and a Cancel button.
- MB_ICONOK: Displays an OK button and an icon.
- MB_ICONCANCEL: Displays an OK button and a Cancel button with a closed circle icon.
- MB_ICONERROR: Displays an OK button and a closed circle icon with an error icon.
- MB_ICONQUESTION: Displays an OK and a Cancel button with a question mark icon.
- MB_SYSTEM_MODAL: The message box is modal.
- MB_APPLICATION_MODAL: The message box is modal, but the application can respond to the WM_QUERYPOS and WM_INITDIALOG messages.
Returns
INT_PTR
The return value of this function depends on the user’s action:
- MB_OK or MB_ICONOK: Returns MB_OK.
- MB_OK or MB_ICONOK or MB_OK or MB_ICONOK: Returns MB_OK.
- MB_CANCEL or MB_ICONCANCEL or MB_ICONCANCEL or MB_ICONCANCEL: Returns MB_OK.
- The user clicks the Cancel button: Returns MB_CANCEL.
- The user clicks the Close button: Returns 0.
Example
// Example code to display a message box with an OK button.
MessageBox( hWnd, "Hello, world!", NULL, MB_OK );