Home

Message Boxes: The Message Dialog

   

Introduction

The MessageDlg() function is the VCLs enhanced message box and it provides a good alternative to the Win32s MessageBox() function:

Scanner

The syntax of the MessageDlg() function is:

int __fastcall MessageDlg(const AnsiString Message,
                          TMsgDlgType IconType,
                          TMsgDlgButtons Buttons,
                          int HelpContext);

 

 

The Icon Type of the Message Dialog

The first argument, Message, is the message addressed to the user. It can be a simple static sentence, a paragraph or any combination of strings. The IconType is an icon used to enhance the dialog box. The icon is set using a constant integer as follows:

Value Icon
mtWarning
mtError
mtInformation
mtConfirmation 
mtCustom None

The Buttons on the Message Dialog

The Buttons argument is used to specify the type(s) of button(s) to display on the dialog box. The buttons are defined using the TMsgDlgButtons set as follows:

Value Button
mbYes Yes
mbNo No
mbOK OK
mbCancel Cancel
mbAbort Abort
mbHelp Help
Value Button
mbRetry Retry
mbIgnore Ignore
mbAll
mbNoToAll
mbYesToAll
   

The last argument is used if there is a help file available, in which case you would specify the particular index related to this message box. This message box uses the name of the project as its caption.

Here is an example:

//---------------------------------------------------------------------------
WINAPI _tWinMain(HINSTANCE hInstance,
				   HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine,
				   int nCmdShow)
{
    MessageDlg(L"All songs on the CD have been copied. Now it will be ejected.",
	       mtInformation, TMsgDlgButtons() << mbOK, 0);
    return 0;
}
//---------------------------------------------------------------------------

This would produce:

Here is another example:

//---------------------------------------------------------------------------
WINAPI _tWinMain(HINSTANCE hInstance,
		   HINSTANCE hPrevInstance, 
		   LPSTR lpCmdLine, 
		   int nCmdShow)
{
    MessageDlg(L"The file C:\\Musics\\tune1.wav"
	       L" that you are trying to upload "
	       L"already exists on the server.\n"
	       L"If you continue, you will replace the recent versions "
	       L"of the files on the server.\n"
	       L"Would you like to upload anyway?",
	       mtConfirmation,
	       TMsgDlgButtons() << mbNoToAll << mbNo
				<< mbYes << mbYesToAll, 0);
    return 0;
}
//---------------------------------------------------------------------------

This would produce:

Message Box

 

Home Copyright © 2010-2011 FunctionX, Inc.