It may be because of the relationship between the focus of work. I have never used the MDI Interface Programming before. Recently I need to write an MDI Program First, let's take a look at MFC for two days,
From Chapter 8, we can understand the relationship between views and Doc. After a deep understanding of MFC, I found that Microsoft's programming framework has always embodied the concept of induction, reuse, and platform-based Development. The vision is far from average.
Now, I will summarize some of the minor problems and solutions that I have encountered, and the experts will not have to read them.
1. the dialog box resources associated with the cformview class must have the child attribute.
A class derived from cformview can be associated with a dialog box resource. However, in this dialog box, the [child] attribute must be selected for the style in attribute settings. Otherwise,
CodeIt can be compiled, but the debug operation will report an asserted error, trace the code, and assert in:
# Ifdef _ debug
// Dialog template must exist and be invisible with ws_child set
If (! _ Afxcheckdialogtemplate (m_lpsztemplatename, true ))
{
Assert (false); // invalid dialog Template Name
Postncdestroy (); // cleanup if Create fails too soon
Return false;
}
# Endif // _ debug
The comments automatically added by MFC already indicate the cause of the assertion: The ws_child flag is required.
The release operation does not show assertion errors, but the control in the dialog box cannot be displayed.
2. cformview is special. A parent form is nested with a subform. Therefore, the instance of the cformview class does not respond to the wm_close message, but only responds to the wm_destroy message.
In addition, if you want to use code to close the current view, you cannot directly: postmessage (wm_close,);
instead, you must first obtain the pointer to the parent form, then, send the wm_close message to the parent form, as shown in the following figure:
getparent ()-> postmessage (wm_close,);
.
the 8-1 figure in chapter 8 of the in-depth introduction to MFC clearly illustrates this situation. The View window is a subwindow of the cchildframe window.