if
MessageDlg(
‘Welcome to my Delphi application. Exit now?‘
,
mtConfirmation, [mbYes, mbNo],
0
) = mrYes
then
begin
Close;
end
;
Messagedlg usage
Dialog Box Type:
Mtwarning-warning dialog box containing exclamation points
Mterror -- error dialog box with Red Cross symbol
Mtinformation -- Information dialog box containing the blue I symbol
Mtconfirmation -- confirmation dialog box with green question mark
Mtcustom -- General dialog box without icons. The title of the dialog box is the program name.
Buttons in the button group:
Mbyes -- mryes or 6
Mbno -- mrno or 7
Mbok -- mrok or 1
Mbcancel -- mrcancel or 2
Mbhelp -- Help button
Mbabort -- mrabort or 3
Mbretry -- mrretry or 4
Mbignore -- mrignore or 5
Mball -- mrall or 8
Mbnotoall -- 9
Mbyestoall -- 10
Procedure tform1.button1click (Sender: tobject );
VaR
S: string;
Begin
If messagedlg ('prompt box ', mtinformation, [mbok, mbyes], 0) = mryes then
Messagebeep (mb_iconexclamation );
End;
Tmsgdlgtype = (mtwarning, mterror, mtinformation, mtconfirmation, mtcustom );
Tmsgdlgbtn = (mbyes, mbno, mbok, mbcancel, mbabort, mbretry, mbignore,
Mball, mbnotoall, mbyestoall, mbhelp );
Const
Mrnone = 0;
Mrok = idok;
Mrcancel = idcancel;
Mrabort = idabort;
Mrretry = idretry;
Mrignore = idignore;
Mryes = idyes;
Mrno = IDNO;
Mrall = mrno + 1;
Mrnotoall = mrall + 1;
Mryestoall = mrnotoall + 1;
Description of messagedlg () Information
All constants in Delphi are placed in consts. Pas. modifying it can achieve the goal of Chinese conversion. For example:
The title of the window displayed by messagedlg () and
The button title is in English, although it does not affect the use, but it seems a bit uncoordinated in a Chinese software.
Find the following content in consts. PAS:
"Smsgdlgwarning"
Set
Smsgdlgwarning = 'warning ';
Smsgdlgerror = 'error ';
Smsgdlginformation = 'information ';
Smsgdlgconfirm = 'Confirm ';
Smsgdlgyes = '& Yes ';
Smsgdlgno = '& no ';
Smsgdlgok = 'OK ';
Smsgdlgcancel = 'cancel ';
Smsgdlghelp = '& help ';
Smsgdlghelpnone = 'no help available ';
Smsgdlghelphelp = 'help ';
Smsgdlgabort = '& abort ';
Smsgdlgretry = '& retry ';
Smsgdlgignore = '& ignore ';
Smsgdlgall = '& all ';
Smsgdlgnotoall = 'n' & O to all ';
Smsgdlgyestoall = 'Yes to & all ';
Change
Smsgdlgwarning = 'Warning ';
Smsgdlgerror = 'error ';
Smsgdlginformation = 'hs ';
Smsgdlgconfirm = 'confirmed ';
Smsgdlgyes = 'Yes (& Y )';
Smsgdlgno = 'no (& N )';
Smsgdlgok = 'OK ';
Smsgdlgcancel = 'cancel ';
Smsgdlghelp = 'help (& H )';
Smsgdlghelpnone = 'no help information ';
Smsgdlghelphelp = 'help ';
Smsgdlgabort = 'abandon (& )';
Smsgdlgretry = 'retry (& R )';
Smsgdlgignore = 'ignore (& I )';
Smsgdlgall = 'all (& )';
Smsgdlgnotoall = 'all (& O )';
Smsgdlgyestoall = 'all are (& )';
Then re-compile consts. PAS and put consts. Duc
Copy the file to the lib and slib sub-directories of Delphi!
Certificate --------------------------------------------------------------------------------------------------------------------------------------------------------
In the MessageBox dialog box, enter the imename attribute of the control to remove the input method. The default value is English input.
The MessageBox dialog box is a commonly used information dialog box. It not only defines the displayed information content and information prompt icons, but also defines the button combination and the title of the dialog box, is a fully functional information dialog box information prompt icon, and can define button combination and the title of the dialog box, is a fully functional information box.
1. function prototype and Parameters
Function MessageBox (hwnd: hwnd; text, caption: pchar; Type: Word): integer;
Hwnd: the parent window handle of the dialog box. The dialog box is displayed in the Delphi Form. You can use the handle attribute of the Form. Otherwise, 0 can be used to directly act as a subwindow of the desktop window.
Text: the string of the information to be displayed.
Caption: The title string of the dialog box.
Type: a constant of the dialog box type.
The return value of this function is an integer used for dialog box button recognition.
2. Type Constants
The type constant of the dialog box can be composed of four constants: button combination, default button, display icon, and running mode.
(1) button combination constant
Mb_ OK = $00000000; // a confirmation button
Mb_okcancel = $00000001; // a confirmation button and a Cancel button
Mb_abortretryignore = $00000002; // an exception termination button, a Retry button, and an ignore button
Mb_yesnocancel = $00000003; // One is a button, the other is a button, and the other is a Cancel button.
Mb_yesno = $00000004; // One is a button and the other is a no button.
Mb_retrycancel = $00000005; // A Retry button and a Cancel button
(2) default button constant
Mb_defbutton1 = $00000000; // The first button is the default button.
Mb_defbutton2 = $00000100; // the second button is the default button.
Mb_defbutton3 = $00000200; // the third button is the default button.
Mb_defbutton4 = $00000300; // The fourth button is the default button.
(3) icon constant
Mb_iconhand = $00000010; // "X" icon
Mb_iconquestion = $00000020; // "?" Icon
Mb_iconexclamation =00000030; // "!" Icon
Mb_iconasterisk = $00000040; // "I" icon
Mb_usericon = $00000080; // user icon
Mb_iconwarning = mb_iconexclamation; // "!" Icon
Mb_iconerror = mb_iconhand; // "X" icon
Mb_iconinformation = mb_iconasterisk; // "I" icon
Mb_iconstop = mb_iconhand; // "X" icon
(4) constant in Running Mode
Mb_applmodal = $00000000; // application mode, which can be switched to another application before the dialog box is closed
Mb_systemmodal = $00001000; // system mode. You must end the dialog box before you can perform other operations.
Mb_taskmodal = $00002000; // task mode, which can be switched to another application before the dialog box is closed
Mb_help = $00004000; // HELP button
3. function return value
0 // dialog box creation failed
Idok = 1 // press OK
Idcancel = 2 // press the cancel button
Idabout = 3 // press the terminate exception button
Idretry = 4 // press the Retry button
Idignore = 5 // press the ignore button
Idyes = 6 // press the "yes" button
IDNO = 7 // Press No
Example: MessageBox (0, 'playing type not selected ', 'error', mb_iconexclamation );
-- Application. MessageBox ('messagebox', 'shanghai', mb_iconwarning + mb_yesno );
-- MessageBox (form1.handle, 'messagebox', 'hs', mb_iconinformation + mb_okcancel );
-- MessageBox (form1.handle, 'messagebox', 'hs', mb_iconinformation + mb_okcancel + mb_defbutton2 );
-- If MessageBox (form1.handle, 'messagebox', 'hs', mb_iconinformation + mb_okcancel) = idok then
Begin
Showmessage ('OK ');
End;