Common Use of MessageBox

Source: Internet
Author: User

I. 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.
Ii. 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
Iii. function return values
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
Iv. Usage
1. MessageBox ("this is the simplest message box! ");
2. MessageBox ("this is a message box with a title! "," Title ");
3. MessageBox ("this is a confirmation message box! "," Title ", mb_okcancel );
4. MessageBox ("this is a warning message box! "," Title ", mb_iconexclamation );
5. MessageBox ("this is a message box with two attributes! "," Title ", mb_iconexclamation | mb_okcancel );
6. If (MessageBox ("a common application", "title", mb_iconexclamation | mb_okcancel) = idcancel)
Return;
Note:
The message box is used in the subclass of cwnd. If not, MessageBox (null, "DDD", "DDD", mb_ OK); or MessageBox (hwnd, "DDD", "DDD", mb_ OK); hwnd is the handle of a window, or afxmessagebox is directly used.
5. DISPLAY variable values in MessageBox
Cstring string;
String. Format ("% d % s", m_age, m_address); // assemble the variable into the string.
MessageBox (string, "message box title", message box type );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.