Differences between afxmessagebox and MessageBox

Source: Internet
Author: User

If you use MFC, use afxmessagebox whenever possible. This global dialog box is the safest and most convenient.
However, in the case of Win32 SDK, only MessageBox can be used.

MessageBox () is a WIN32API function. The latter is a global function in MFC. afxmessagebox () can be used wherever MessageBox () can be used in MFC ().

Afxmessagebox is used for debugging many other times.
Afxmessagebox is more convenient than MessageBox!
MessageBox is more flexible than afxmessagebox (such as specifying the dialog box title )!
MessageBox is a Win32 API that can be used directly. afxmessagebox is an API of MFC and must be supported by MFC.

If you use MFC, use afxmessagebox whenever possible. This global dialog box is the safest and most convenient. However, in the case of Win32 SDK, only MessageBox can be used.

The beginning of afx is a global function, that is, afxmessagebox can be used in whatever program, while MessageBox can only be used in cwnd and Its Derived classes.

MessageBox can set titles at will, while afxmessagebox cannot.

 

Differences between the two functions:

Afxmessagebox is a global function provided by the MFC Library and provides multiple reloads. MessageBox is a standard Windows API function.

The afxmessagebox () function can be used in any class, while the MessageBox () function can only be used in the inheritance class of the cwnd class. In addition, the number of dimensions of the afxmessagebox () function is not as rich as the number of dimensions of the MessageBox () function, so the latter is more flexible than the former.
Afxmessagebox does not control the title of the message box. It is often used for internal data output or warning during program debugging. MessageBox is more formal than callback and is often used in the version number of the application to be submitted, the ability to control the title content without the need to refer to the title as a runable file name with unknown meanings.


The two are described as follows:

Afxmessagebox function prototype


Int afxmessagebox (lpctstr lpsztext, uint ntype = mb_ OK, uint nidhelp = 0 );
Int afxapi afxmessagebox (uint nidprompt, uint ntype = mb_ OK, uint nidhelp = (uint)-1 );


In the first form, lpsztext indicates the text displayed inside the message box. The title of the message box is the name of the runable file (such as Hello) of the application ).

In another form, nidprompt is the ID of the text string to be displayed in the string table. When a function is called, it automatically loads strings from the string table and displays them in the message box. Ntype is a combination of the button style and Icon style displayed in the message box. It can combine various styles with the | (OR) operator.

Button Style
The message boxes of mb_abortretryignore show abort, retry, and ignorebutton.
Mb_ OK display okbutton
Mb_okcancel: OK and cancelbutton
Mb_retrycancel: displays retry and cancelbutton
Mb_yesno: Yes and nobutton are displayed.
Mb_yesnocancel indicates yes, no, and cancelbutton.
Icon Style
Mb_iconinformation displays an I icon, indicating a prompt
Mb_iconexclamation displays an exclamation point, indicating a warning.
Mb_iconstop: displays the hand icon, indicating a warning or serious error.
Mb_iconquestion: displays the question mark icon, indicating a question

 

Similar to afxmessagebox, MessageBox is a member function of cwnd class:


Use of MessageBox:

Int MessageBox (maid, maid = NULL, uint ntype = mb_ OK );

Number of shards:

Lpsztext: Message Body
Lpszcaption: Message Box title (not available by default)
Ntype: message frame style

 

Example:

Afxmessagebox ("Are you sure? ", Mb_yesno | mb_iconquestion );
Int A = MessageBox ("are you sure you want to delete it? "," Warning !! ", Mb_yesno | mb_iconwarning );
If (A = idyes)
Afxmessagebox ("yes ");
Else
Afxmessagebox ("no ");


 

Differences between MessageBox functions in API and MFC:

The API definition is as follows:
Int MessageBox (
Hwnd, // handle of owner window
Lptstr lptext, // address of text in message box
Maid, // address of title of message box
Uint utype // style of message box
);

The definitions in MFC are as follows:
Cwnd: MessageBox
Int MessageBox (

Lpctstr lpsztext,

Lpctstr lpszcaption = NULL,

Uint ntype = mb_ OK

);

Therefore, in MFC, only the first vertex number is missing. At the same time, both the Third and Fourth have default values. This is the difference between them. Others are the same.

At the same time, the one that calls the API in the MFC window class is written as follows:
: MessageBox (null, "MSG", "caption", mb_ OK );

 

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.