MessageBox,: MessageBox, afxmessagebox three differences.

Source: Internet
Author: User

Differences among MessageBox,: MessageBox, and afxmessagebox

I used to know the differences between these functions, but I didn't go into details. I haven't written VC for a long time.ProgramThe error occurred while using MessageBox. I found some information on the Internet and understood the differences between the three functions.Article(Refer to the materials written by a large number of others ). This allows you to maintain a long memory and also helps people who do not know much about it.

 

The essential differences are as follows:

Windows API: MessageBox ();

 

Cwnd: MessageBox ();

 

MFC: afxmessagebox ();

 

Cwnd: MessageBox () and afxmessagebox () are both encapsulation of the API function MessageBox.

 

Instructions on Whether to handle hwnd:

1) MessageBox is an API, so it requires the hwnd parameter to specify its form.

 

2) cwnd: MessageBox () is a member function of cwnd. It requires MessageBox to be used only in the cwnd class and its subclass. It does not require the hwnd parameter, cwnd indicates the window to which it belongs. Therefore, cwnd: MessageBox () is equivalent to: MessageBox (hwnd.

 

3) The global function in afxmessagebox () MFC has no handle to the hwnd parameter. Afxmessagebox () can be used wherever MessageBox () can be used, but afxmessagebox cannot set the message box title (its default title is the executable file name of the application ).

 

Suggestions:

1) the API MessageBox function is used in a non-cwnd class, but it is inconvenient to use. You must specify the title, handle, and style. Otherwise, select cwnd: MessageBox () or afxmessagebox, they are easy to use.

2) MessageBox is a modal dialog box. If you do not confirm that the program is not running, it will block your current thread, unless your program is a multi-threaded program, otherwise, only the wait mode dialog box is confirmed.

3) If you use MFC, try to use afxmessagebox, because the global dialog box is the safest and most convenient.

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.