MSGBOX statement

Purpose

Display a message box containing a text string and optional title, using one or more styles.

Syntax

MSGBOX txt$ [, [style%], title$]

? txt$ [, [style%], title$]

Remarks

The MSGBOX statement comprises the following elements:

txt$

Text to display within the message box.

style&

Optional parameter which determines the appearance of the message box. Some styles may be combined (OR'ed together) to specify the button and icon displayed in the message box. If style& is omitted, PowerBASIC substitutes %MB_OK. The following are some of the more common styles used with the MSGBOX statement (also see the MSGBOX function for more information):

%MB_OK

Display OK button (default)

%MB_ICONERROR

Display Error icon (stop sign)

%MB_ICONINFORMATION

Display Information icon ("i")

%MB_ICONWARNING

Display Warning icon (exclamation)

%MB_APPLMODAL

Application Modal - Despite the name, the user can continue to interact with other dialogs without dismissing the MSGBOX. (default)

%MB_SYSTEMMODAL

System Modal - Operates identically to %MB_APPLMODAL, except the MSGBOX is given the %WS_EX_TOPMOST style so that it remains above all other windows and dialogs.

%MB_TASKMODAL

Task Modal - All top-level windows belonging to the current application are disabled until the MSGBOX is dismissed. %MB_TASKMODAL is commonly used to display a truly modal MSGBOX.

Additional styles may be found in WIN32API.INC, in the section prefixed with %MB_. If you are interested in which button the user selects, use a MSGBOX function rather than a MSGBOX statement.

title$

Determines the title to be displayed in the caption of the message box. If title$ is not specified, "PowerBASIC" is used automatically.

The MSGBOX statement may be represented by the query (?) character as a shortcut. This is similar to the behavior in the PowerBASIC Console Compiler (PB/CC), where the query character is recognized as a synonym for the PRINT statement. This can simplify the creation of certain test code, since the query character provides similar functionality in both compilers.

Restrictions

Strings displayed by the MSGBOX function are displayed only up to the first $NUL character, if any.

See also

INPUTBOX$, MSGBOX function

Example

MSGBOX "Got here, hit OK to continue",, "Title of subroutine 123"

MSGBOX "Current value of X% is: " & STR$(x%)

MSGBOX "Paused, click OK to continue!"

MSGBOX "Click OK to reboot the universe…", %MB_TASKMODAL OR %MB_ICONERROR, "Reality has crashed!"