MessageBox function
Displays a modal dialog with the given text, caption, icon and buttons.
Declaration
function MessageBox(hWnd: HWND; lpText: PChar; lpCaption: PChar;
uType: Cardinal=MB_OK): IntegerDescription
MessageBox is an
Integer function used to display a
modal dialog with the text, caption, icon and buttons specified using the
arguments to the routine. It provides the common routine in the LCL interface
used to access the platform-specific implementation of the routine for the
widgetset class.
hWnd contains the handle for the window which is the owner of the
dialog created and executed in the routine. The default value (0) indicates a
handle is not available or not assigned for the owner window.
lpText is a PChar value with the text displayed on the modal
dialog. Multi-line text can be used by embedding the end-of-line character
sequence in the content.
lpCaption is a PChar value with the title displayed on the modal
dialog.
uType is a Cardinal value which identifies the content and
behavior for the modal dialog. It consists of flag values which can be OR-ed
together and passed to the widgetset implementation. uType can contain flag
values from the following flag groups:
Buttons (defined in
lcltype.pp)
- MB_OK ($00000000)
- Displays an OK button. This is the default behavior for the Windows platform.
- MB_OKCANCEL ($00000001)
- The message box contains two push buttons: OK and Cancel.
- MB_ABORTRETRYIGNORE ($00000002)
- Displays Abort, Retry, and Ignore buttons.
- MB_YESNOCANCEL ($00000003)
- Displays Yes, No, and Cancel buttons.
- MB_YESNO ($00000004)
- Displays Yes and No buttons.
- MB_RETRYCANCEL ($00000005)
- Displays Retry and Cancel buttons.
- MB_MB_CANCELTRYCONTINUE ($00000006)
- Not supported in the current LCL version.
- MB_HELP ($00004000)
- Displays a Help button on the dialog. Sends a help message to the owner window in hWnd when it has a non-zero value.
Icons (defined in
lcltype.pp)
- MB_ICONSTOP, MB_ICONERROR, MB_ICONHAND ($00000010)
- Displays a stop sign icon on the dialog.
- MB_ICONQUESTION ($00000020)
- Displays a question mark icon on the dialog.
- MB_ICONEXCLAMATION, MB_ICONWARNING ($00000030)
- Displays an exclamation point icon on the dialog.
- MB_ICONINFORMATION, MB_ICONASTERISK ($00000040)
- Displays a lowercase "i" icon on the dialog.
Default Buttons (defined in
lcltype.pp)
- MB_DEFBUTTON1 ($00000000)
- The first button is the default button. This is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.
- MB_DEFBUTTON2 ($00000100)
- The second button is the default button.
- MB_DEFBUTTON3 ($00000200)
- The third button is the default button.
- MB_DEFBUTTON4 ($00000300)
- The fourth button is the default button.
The return value indicates the button selected on the modal dialog, and can
be identified using the following Integer constants defined in
lcltype.pp:
- IDOK, ID_OK (1)
- IDCANCEL, ID_CANCEL (2)
- IDABORT, ID_ABORT (3)
- IDRETRY, ID_RETRY (4)
- IDIGNORE, ID_IGNORE (5)
- IDYES, ID_YES (6)
- IDNO, ID_NO (7)
- IDCLOSE, ID_CLOSE (8)
- IDHELP, ID_HELP (9)
For example:
uses LCLIntf, LCLType;
// ...
function ShowResourceNotAvailableMessageBox: Integer;
begin
Result := MessageBox(0,
PChar('Resource not available.'+#10+'Try again?'),
PChar('Account Details'),
MB_ICONWARNING or MB_ABORTRETRYIGNORE or MB_DEFBUTTON2);
case Result of
IDABORT: // needs to be implemented
IDRETRY: // needs to be implemented
IDIGNORE: // needs to be implemented
end;
end;See also
An experiment, built from Lazarus main 2dfa93c66e of 10-22-2026. Not the official Lazarus documentation.
