MessageBoxA Function
The MessageBoxA function creates, displays, and operates a message box. A message box is a dialog box that displays a specified amount of information, with a window-defined icon, accompanied by a set of application-defined buttons, to the user.
Syntax
int MessageBoxA(
[in, optional] HWND hWnd,
[in, optional] LPCSTR lpText,
[in, optional] LPCSTR lpCaption,
[in] UINT uType
);
Parameters
hWnd-
A handle to the owner window of the message box to be created. If this parameter is
NULL, the message box has no owner window. lpText- A null-terminated string that contains the message to be displayed.
lpCaption-
A null-terminated string that contains the desired title for the message box. If this parameter is
NULL, the title will be "Error". uType- A set of bit flags that determine the content and behavior of the dialog box. This parameter can be a combination of the flags described in "Message Box Styles".
Return Value
If the function succeeds, the return value is one of the following integer values, indicating which button the user clicked.
| Return Value | Meaning |
|---|---|
IDOK |
OK button was selected. |
IDCANCEL |
Cancel button was selected. |
IDABORT |
Abort button was selected. |
IDRETRY |
Retry button was selected. |
IDIGNORE |
Ignore button was selected. |
IDYES |
Yes button was selected. |
IDNO |
No button was selected. |
If the function fails (for example, because it cannot allocate memory for the message box), the return value is less than zero.
Remarks
The MessageBoxA function is the ANSI version of the MessageBox function. For Unicode applications, use MessageBoxW.
If an application passes NULL for the hWnd parameter, the message box is created as a window with no owner.
Note
For a comprehensive list of message box styles, refer to the Message Box Styles documentation.
Example
#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
int msgboxID = MessageBoxA(
NULL,
"This is the message text.",
"My Application Title",
MB_OK | MB_ICONINFORMATION
);
switch (msgboxID) {
case IDOK:
// User clicked OK
break;
}
return 0;
}
Requirements
| Requirement | Value |
|---|---|
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Header | winuser.h (include windows.h) |
| Library | User32.lib |
| DLL | User32.dll |