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

The Windows Message Box

A message box is a predefined dialog box provided by Windows that displays a message to the user and, optionally, one or more buttons that allow the user to respond. Message boxes are commonly used to provide information, display warnings or error messages, request confirmation before performing an action, or ask the user to make a simple choice.

Message boxes are created using the MessageBox() function, which requires four parameters. 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;
}

Customising the Windows Message Box

The standard Windows MessageBox() function provides only limited customisation. Although developers can choose the buttons, icons, default button, and modality, they cannot directly modify the layout, fonts, colours, or add additional controls.

For more advanced customisation, a Windows hook procedure can be used to intercept the creation of the message box. One approach is to install a Computer-Based Training (CBT) hook using the WH_CBT hook type. A CBT hook allows an application to receive notifications when a window is created, activated, moved, or destroyed.

By intercepting the message box as it is being created, a CBT hook can be used to modify certain aspects of its appearance or behaviour, such as changing the window title, repositioning the dialog, altering the captions of its buttons, or performing additional initialisation before the message box is displayed.

Although using a WH_CBT hook provides greater flexibility than the standard MessageBox() function, it also increases the complexity of the application. Consequently, hooks are generally reserved for specialised applications. When extensive customisation is required, it is usually preferable to create a custom dialog box instead of modifying a standard message box.