Back to Devexpress

dxMessageBox(string,string,Integer,TdxMessageDialogHyperlinkClickDelegate,TdxMessageDialogShowHyperlinkHintDelegate) Method

vcl-dxmessagedialog-dot-dxmessagebox-x28-4764ce2f-x29.md

latest10.8 KB
Original Source

dxMessageBox(string,string,Integer,TdxMessageDialogHyperlinkClickDelegate,TdxMessageDialogShowHyperlinkHintDelegate) Method

Opens a message dialog box that displays a specified message, title, and buttons (configured using a combination of flags).

Declaration

delphi
function dxMessageBox(const AMessage: string; const ATitle: string; AFlags: Integer; const AHyperlinkClickProc: TdxMessageDialogHyperlinkClickDelegate = nil; const AShowHyperlinkHintProc: TdxMessageDialogShowHyperlinkHintDelegate = nil): Integer;

Parameters

NameTypeDescription
AMessagestring

Message dialog box content. The AMessage parameter value initializes the created form’s Message property.

The AMessage parameter supports a set of BBCode-inspired tags that allow you to format message box content.

| | ATitle | string |

A message dialog box caption. You can pass an empty string as the ATitle parameter to display a predefined caption.

| | AFlags | Integer |

A combination of flags that define message dialog box behavior and available UI elements.

Refer to the list of supported flags in the Remarks section.

| | AHyperlinkClickProc | TdxMessageDialogHyperlinkClickDelegate |

Optional. Specifies a procedure that handles a click on a hyperlink within the displayed message. The AHyperlinkClickProc parameter value initializes the HyperlinkClickProc property of the created message dialog box form.

You can define a click handler procedure to identify the clicked hyperlink and prevent certain links from being activated.

Tip

Refer to the TdxMessageDialogHyperlinkClickDelegate procedural type description for detailed information and a code example.

| | AShowHyperlinkHintProc | TdxMessageDialogShowHyperlinkHintDelegate |

Optional. Specifies a procedure that handles a hyperlink hint display event. The AShowHyperlinkHintProc parameter value initializes the ShowHyperlinkHintProc property of the created message dialog box form.

You can define a hyperlink hint handler procedure to change the predefined hint message (the hyperlink target URI) depending on certain conditions in your application.

Tip

Refer to the TdxMessageDialogShowHyperlinkHintDelegate procedural type description for detailed information and a code example.

|

Returns

TypeDescription
Integer

The ID of the button clicked to close the message box.

The function returns 0 if it failed to create a message box, and 2 if a user clicked the Close button or pressed Esc.

Refer to the list of possible return values in the Remarks section.

|

Remarks

Call the dxMessageBox function to open a generic dialog box with a title, message and one or more buttons.

The created message dialog box has the mdsMessageBox style.

Code Examples

Display a Generic Error Message Box

The following code example displays a generic message box with a predefined Error caption, an OK button, and an error icon:

delphi
uses
  dxMessageDialog, // Declares the dxMessageBox method
  Winapi.Windows; // Declares WinAPI constants
// ...

procedure TMyForm.DemonstrateGenericDxMessageBox;
var
  AFlags: Integer;
  ATitle: string;
begin
  // Define a message box layout with an "OK" button and an "Error" title
  AFlags := MB_OK or MB_ICONERROR;
  ATitle := ''; // Retains the "Error" title defined by the MB_ICONERROR flag
  dxMessageBox('Incorrect operation!', ATitle, AFlags); // Displays a generic error message box
end;
cpp
#include "dxMessageDialog.hpp" // Declares the dxMessageBox method
#include <Winapi.Windows.hpp> // Declares WinAPI constants

// Add the following linker directive to the corresponding CPP source file:
#pragma link "dxMessageDialog" // Required to use dxMessageDialog.hpp declarations
// ...

void __fastcall TMyForm::DemonstrateGenericDxMessageBox()
{
  int AFlags;
  UnicodeString ATitle;

  // Define a message box layout with an "OK" button and an "Error" title
  AFlags = MB_OK | MB_ICONERROR;
  ATitle = ""; // Retains the "Error" title defined by the MB_ICONERROR flag
  dxMessageBox("Incorrect operation!", ATitle, AFlags); // Displays a generic error message box
}

Display a Message Box and Identify the User Action

The following code example opens a message dialog box with a formatted message and a configured layout, and identifies the action used to close the message box:

delphi
uses
  dxMessageDialog, // Declares the dxMessageBox method
  Winapi.Windows; // Declares WinAPI constants
// ...

procedure TMyForm.DemonstrateDxMessageBox1;
var
  ATitle, AMessage, AHelpURL: string;
  AFlags, ACloseAction: Integer;
begin
  // Define a formatted message with a hyperlink (using the BBCode-inspired markup)
  AHelpURL := 'https://docs.devexpress.com/VCL/dxMessageDialog.dxMessageBox(4764CE2F)';
  AMessage := '[URL=' + AHelpURL + ']dxMessageBox[/URL] opens a message dialog box ' +
    'with a title ([B]ATitle[/B]), message ([B]AMessage[/B]), ' +
    'and layout configured using a combination of flags ([B]AFlags[/B]).';
  ATitle := 'Message Box Example'; // Defines a message box title

  // Define a message box layout with OK and Cancel buttons,
  // move focus to Cancel, and display the Information icon
  AFlags := MB_OKCANCEL or MB_DEFBUTTON2 or MB_ICONINFORMATION;
  ACloseAction := dxMessageBox(AMessage, ATitle, AFlags); // Displays a message box

  // Identify the action used to close the message box
  case ACloseAction of
    IDOK: Caption := 'OK is clicked';
    IDCANCEL: Caption := 'Cancel is clicked';
    0: Caption := 'Failed to create a message box';
  end;
end;
cpp
#include "dxMessageDialog.hpp" // Declares the dxMessageBox method
#include <Winapi.Windows.hpp> // Declares WinAPI constants

// Add the following linker directive to the corresponding CPP source file:
#pragma link "dxMessageDialog" // Required to use dxMessageDialog.hpp declarations
// ...

void __fastcall TMyForm::DemonstrateDxMessageBox1()
{
  UnicodeString ATitle, AMessage, AHelpURL;
  int AFlags, ACloseAction;

  // Define a formatted message with a hyperlink (using the BBCode-inspired markup)
  AHelpURL = "https://docs.devexpress.com/VCL/dxMessageDialog.dxMessageBox(4764CE2F)";
  AMessage =
    "[URL=" + AHelpURL + "]dxMessageBox[/URL] opens a message dialog box "
    "with a title ([B]ATitle[/B]), message ([B]AMessage[/B]), "
    "and layout configured using a combination of flags ([B]AFlags[/B]).";
  ATitle = "Message Box Example"; // Defines a message box title

  // Define a message box layout with OK and Cancel buttons,
  // move focus to Cancel, and display the Information icon
  AFlags = MB_OKCANCEL | MB_DEFBUTTON2 | MB_ICONINFORMATION;
  ACloseAction = dxMessageBox(AMessage, ATitle, AFlags); // Displays a message box

  // Identify the action used to close the message box
  switch (ACloseAction)
  {
    case IDOK: Caption = "OK is clicked"; break;
    case IDCANCEL: Caption = "Cancel is clicked"; break;
    case 0: Caption = "Failed to create a message box"; break;
  }
}

Supported Flags

MB_OKThe message box has only the OK button.MB_RETRYCANCELThe message box has two buttons: Retry and Cancel.MB_YESNOThe message box has two buttons: Yes and No.MB_YESNOCANCELThe message box has three buttons: Yes , No , and Cancel.MB_ABORTRETRYIGNOREThe message box has three buttons: Abort , Retry , and Ignore.MB_OKCANCELThe message box has two buttons: OK and Cancel.MB_DEFBUTTON1Explicitly defines the first button as default. The first button is default unless the MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 flag is set.MB_DEFBUTTON2Sets the second button as default.MB_DEFBUTTON3Sets the third button as default.MB_DEFBUTTON4Sets the fourth button as default.MB_ICONWARNING or MB_ICONEXCLAMATIONThe message box displays an exclamation sign icon.MB_ICONERROR, MB_ICONHAND, or MB_ICONSTOPThe message box displays a stop sign button.MB_ICONINFORMATION or MB_ICONASTERISKThe message box displays the icon that consists of a lowercase i in a circle.MB_ICONQUESTIONThe message box displays a question sign icon.MB_RTLREADINGThe message box changes the direction of message and caption text to right-to-left.MB_TOPMOSTThe message box has the WS_EX_TOPMOST window style.

Return Values

The return value identifies the action used to close the message box:

IDOKA user clicked the OK button to close the message box.IDCANCELA user clicked the Cancel or Close button, or pressed Esc to close the message box.IDABORTA user clicked the Abort button to close the message box.IDRETRYA user clicked the Retry button to close the message box.IDIGNOREA user clicked the Ignore button to close the message box.IDYESA user clicked the Yes button to close the message box.IDNOA user clicked the No button to close the message box. See Also

Message Dialog Boxes

TdxMessageDialogForm.Create Constructor

BBCode-Inspired Text Formatting Markup

dxMessageDialog Unit