Your browser doesn't support JavaScript The Windows Message Box - Windows Programming

The Windows Message Box

The Windows message box is a simple modal dialog box displaying a message and may include some selection options. They are typically used to inform the user that an event has taken place. The MessageBox function takes 5 parameters: a parent handle, a title, a message, and a selection option. If the parent handle is NULL, the message box will be modeless. If a handle for a parent window is specified, the MessageBox can be Modal to the parent window.

To create a message box, use the API function MessageBox(). The prototype for this function is

int MessageBox(HWND hWnd,LPCTSTR lpText,LPCTSTR lpCaption,UINT uType);

where
hWnd – is 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 – The message to be displayed.
lpCaption – Contains dialog box title. If this parameter is NULL, the default title is Error
uType – defines the contents and behaviour of the dialog box and will be a combination of several different flag values but some of the more common values are
MB_ABORTRETRYIGNORE- The message box contains three pushbuttons: Abort, Retry, and Ignore.
MB_ICONEXCLAMATION-An exclamation-point icon appears in the message box.
MB_ICONERROR-A stop-sign icon appears in the message box.
MB_ICONINFORMATION – A lowercase letter 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 – The message box contains one pushbutton: OK. This is the default.
MB_OKCANCEL – The message box contains two push buttons: OK and Cancel.
MB_RETRYCANCEL – The message box contains two push buttons: Retry and Cancel.MB_YESNO – The message box contains two push buttons: Yes and No.
MB_YESNOCANCEL – The message box contains three pushbuttons: Yes, No, and Cancel.
The return value will depend on the type of message box selected but will be one of the following: IDABORT, IDCANCEL, IDCONTINUE, IDIGNORE, IDNO, IDOK, IDRETRY, IDYES

For further detailed reading
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox

The following short program displays a simple ‘hello world’ message box

#include <windows.h>
int APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmdLine, int nCmdShow )
{
    MessageBox( NULL, TEXT("Hello, World!"), TEXT("Hi!"), MB_OK );
    return 0;
}

Example

Customising the Windows Message Box

Although the MessageBox API does not offer the same options for customisation as the standard controls, MessageBox messages can be intercepted by registering a Windows hook. To this end, WM_CBT hook is perfect for changing the behaviour and appearance of a message box without adding too much overhead.