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.