Creates, displays, and operates a message box. The message box contains application-defined message text and title, any icon, and any combination of predefined push buttons.

MessageBoxEx(cText [, nFlags [, cCaption [, nHwnd [, cnIconResource [, nHInstance [, nHelpContextId [, nLanguageId]]]]]]])

Parameters

cText

Specifies the text that appears in the dialog box.

Note

The VFP MESSAGEBOX( ) function allows to pass an expression of any type in this parameter - this function does NOT!
The value passed has to be a string, just use TRANSFORM( ) or other formatting functions to create a string out of an expression.

nFlags (optional)

default = 0

The nFlags parameter controls the appearance and behaviour of the message box.

Buttons.
ValueDescription
MB_OKOK button only
MB_OKCANCELOK and Cancel buttons
MB_ABORTRETRYIGNOREAbort, Retry, and Ignore buttons
MB_YESNOCANCELYes, No, and Cancel buttons
MB_YESNOYes and No buttons
MB_RETRYCANCELRetry and Cancel buttons

Icon
ValueDescription
MB_ICONSTOPOK button only
MB_ICONQUESTIONOK and Cancel buttons
MB_ICONEXCLAMATIONAbort, Retry, and Ignore buttons
MB_ICONINFORMATIONYes, No, and Cancel buttons

Default button.
ValueDescription
MB_DEFBUTTON1The first button is the default button.

MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.
MB_DEFBUTTON2 Second button is default.
MB_DEFBUTTON3Third button is default.
MB_DEFBUTTON4The fourth button is the default button.

Modality of the dialog box.
ValueDescription
MB_APPLMODALThe user must respond to the message box before continuing work in the window identified by the nWnd parameter. However, the user can move to the windows of other threads and work in those windows.

Depending on the hierarchy of windows in the application, the user may be able to move to other windows within the thread. All child windows of the parent of the message box are automatically disabled, but pop-up windows are not.

MB_APPLMODAL is the default if neither MB_SYSTEMMODAL nor MB_TASKMODAL is specified.
MB_SYSTEMMODALSame as MB_APPLMODAL except that the message box has the WS_EX_TOPMOST style. Use system-modal message boxes to notify the user of serious, potentially damaging errors that require immediate attention (for example, running out of memory). This flag has no effect on the user's ability to interact with windows other than those associated with nHwnd.
MB_TASKMODALSame as MB_APPLMODAL except that all the top-level windows belonging to the current thread are disabled if the nWnd parameter is 0. Use this flag when the calling application or library does not have a window handle available but still needs to prevent input to other windows in the calling thread without suspending other threads.

Various other options.
ValueDescription
MB_DEFAULT_DESKTOP_ONLYSame as desktop of the interactive window station. For more information, see Window Stations.

If the current input desktop is not the default desktop, MessageBox does not return until the user switches to the default desktop.
MB_RIGHTThe text is right-justified.
MB_RTLREADINDDisplays message and caption text using right-to-left reading order on Hebrew and Arabic systems.
MB_SETFOREGROUNDThe message box becomes the foreground window. Internally, the system calls the SetForegroundWindow function for the message box.
MB_TOPMOSTThe message box is created with the WS_EX_TOPMOST window style.
MB_SERVICE_NOTIFICATIONThe caller is a service notifying the user of an event. The function displays a message box on the current active desktop, even if there is no user logged on to the computer. Terminal Services: If the calling thread has an impersonation token, the function directs the message box to the session specified in the impersonation token. If this flag is set, the nWnd parameter must be 0. This is so that the message box can appear on a desktop other than the desktop corresponding to the nWnd.

For information on security considerations in regard to using this flag, see Interactive Services. In particular, be aware that this flag can produce interactive content on a locked desktop and should therefore be used for only a very limited set of scenarios, such as resource exhaustion.
cCaption (optional)

default = NULL

The message box title. If this member is NULL, the default title "Error" is used.

nHwnd (optional)

default = NULL

A handle to the owner window.

If nHwnd is NULL or omitted the current active window is set as the owner window.
You can also specify 0 if the dialog box should not have an owner window.

cnIconResource (optional)

default = NULL

Identifies a custom icon resource.

This parameter can be either a string or an integer resource identifier.
To load one of the standard system-defined icons pass NULL in the nHInstance parameter and specify one of the values listed with the LoadIcon function.

nHInstance (optional)

default = NULL | HINSTANCE of the current executable

A handle to the module that contains the icon resource identified by the cnIconResource parameter.

If you omit this parameter parameter or pass NULL but specify a custom icon in the cnIconResource parameter
nHInstance defaults to the HINSTANCE of the current executable.

Note

The HINSTACE/HMODULE of a module (dll) can be retrieved with the GetModuleHandle or LoadLibray function.

nHelpContextId (optional)

default = 0

Identifies a help context.

If a help event occurs, this value is passed to the owner window.

nLanguageId (optional)

default = GetUserDefaultUILanguage()

The language in which to display the text contained in the predefined push buttons.

For a list of supported language identifiers, see Language Identifiers. Note that each localized release of Windows typically contains resources only for a limited set of languages. Thus, for example, the U.S. version offers LANG_ENGLISH, the French version offers LANG_FRENCH, the German version offers LANG_GERMAN, and the Japanese version offers LANG_JAPANESE. Each version offers LANG_NEUTRAL. This limits the set of values that can be used with the nLanguageId parameter. Before specifying a language identifier, you should enumerate the locales that are installed on a system.

Return Value

If the function succeeds, the return value is one of the following menu-item values.

If a message box has a Cancel button, the function returns the IDCANCEL value if either the ESC key is pressed or the Cancel button is selected. If the message box has no Cancel button, pressing ESC has no effect.

If there is not enough memory to create the message box, error 43 is raised.

ValueDescription
IDOKThe OK button was selected.
IDCANCELThe Cancel button was selected.
IDABORTThe Abort button was selected.
IDRETRYThe Retry button was selected.
IDIGNOREThe Ignore button was selected.
IDYESThe Yes button was selected.
IDNOThe No button was selected.
IDTRYAGAINThe Try Again button was selected.
IDCONTINUEThe Continue button was selected.

See Also

Reference

GetOpenFileName
GetSaveFileName
SHBrowseFolder

Used WinApi functions

MessageBoxIndirect
GetUserDefaultUILanguage
GetModuleHandle