Previous Topic: InputBox - Create, Display, and Operate a Message Box WindowNext Topic: ProgressBar - Set the Progress Bar


MessageBox or MsgBox - Display a Message Box Window

Valid on Windows and Windows CE

The MessageBox or MsgBox function displays a message box window. The message box contains a message, a title, and any combination of the predefined buttons described by the style parameter.

Instead of MessageBox, you can use MsgBox to call the function.

Function format:

MessageBox(message as String, title as String, style as Integer) as Integer
MessageBox(message as String, title as String) as Integer
MessageBox(message as String, style as Integer) as Integer
MessageBox(message as String) as Integer
message

Identifies the string containing the message that is to be displayed.

title

Identifies an optional string containing the message box title.

Default: DMS

style

Identifies an optional integer specifying the contents and behavior of the message box. The style parameter can be any of the following predefined constants:

MB_OK

Adds box with button OK (Default)

MB_OKCANCEL

Adds box with buttons OK and Cancel

MB_YESNO

Adds box with buttons Yes and No

MB_RETRYCANCEL

Adds box with buttons Retry and Cancel

MB_YESNOCANCEL

Adds box with buttons Yes, No, and Cancel

MB_ABORTRETRYIGNORE

Adds box with buttons Abort, Retry, and Ignore

Constants for MessageBox Modality

By default, the user must respond to the message box before continuing work in the current window; however, the user can move to, and work in, windows of other applications.

MB_SYSTEMMODAL

All applications are suspended until the user responds to the message box. System modal message boxes are used to notify the user of serious, potentially damaging errors that require immediate attention.

Constants for MessageBox Icons

The default is as follows: No icon is shown.

MB_ICONEXCLAMATION

Adds an exclamation point icon appears in the message box.

MB_ICONINFORMATION

Adds an icon consisting of an "i" in a circle appears in the message box.

MB_ICONQUESTION

Adds a question-mark icon in the message box.

MB_ICONSTOP

Adds a stop sign icon (white "X" in a red circle) appears in the message box.

Constants for MessageBox Default Buttons

The default is as follows. The first button is the default.

MB_DEFBUTTON2

Makes the second button default.

MB_DEFBUTTON3

Makes the third button default.

Other Constants

MB_SETFOREGROUND

Sets the message box as the foreground window. If this is not coded, the current foreground window remains in the foreground.

You can combine each constant of one group with any constant of another group. For example, to display a message box with Abort, Retry, and Ignore (default) buttons, and a stop sign icon, and you want to suspend all applications until the user responds, code using the following style:

MB_ABORTRETRYIGNORE + MB_DEFBUTTON3 + MB_ICONSTOP + MB_SYSTEMMODAL

If the style parameter is omitted, MB_OK is assumed and the message box contains only the OK button.

If there is not enough memory to create the message box, the return value of the function is zero. Otherwise, it is one of the following button values returned by the message box:

IDOK

Value 1; the OK button was clicked.

IDCANCEL

Value 2; the Cancel button (or keyboard Esc key). was clicked.

IDABORT

Value 3; the Abort button was clicked.

IDRETRY

Value 4; the Retry button was clicked.

IDIGNORE

Value 5; the Ignore button was clicked.

IDYES

Value 6; the Yes button was clicked.

IDNO

Value 7; the No button was clicked.

Example:

This example checks with the user for creating a backup copy of the config.sys file, and creates the backup, if required.

Dim Src,Dst as string
Dim Question as string

Question="Do you want to make a backup of your config.sys?"

if MessageBox(Question,MB_YESNO)=IDYES then
	Src="C:\CONFIG.SYS"
	Dst="C:\CONFIG.BAK"
	if CopyFile(Src,Dst,TRUE) then MessageBox("CONFIG.BAK created.")
end if