Cdoctemplate: createnewframe () Function in use MFC Multi-document applicationsProgram( MDI ) Is the document ( Document ) Create other views ( Views ), Createnewframe () The function prototype is as follows:
Cframewnd * cdoctemplate: createnewframe (cdocument *, cframewnd *)
To call this function, you must specifyCdocument Object Pointer (determine the view to be created by the function) and a frame window pointer (used to copy the properties of the window). Generally, the second parameter isNull.
When the application callsCreatenewframe () This function creates a new framework window and a view in the window.
To better understand how to use Createnewframe () For more information, see the following two examples.
The first example is MFC Source codeIn Winmdi. cpp File. Winmdi. cpp Defined Cmidframewnd: onwindownew () Function. This function is called. Createnewframe () Adds other frameworks and views to a specified document. Each time you select New The application calls Onwindownew () .
Onwindownew () The function contains the following two important rows:Code:
Cframewnd * pframe = ptemplate-> createnewframe (pdocument, pactivechild );
Ptemplate-> initialupdateframe (pframe, pdocument );
This Code creates and displays the new Framework Window and document view.
MFC docm Ulti. cpp file. cmultidoctemplate: opendocumentfile () the function contains the following code:
Cframewnd * pframe = createnewframe (pdocument, null );
Note: The second parameter is Null Because Opendocumentfile () Function Design assumes that the programmer is not interested in copying other frameworks that contain the document view.
Chkbook The example also demonstrates how to create additional frameworks and views for the document. Chkbook. cpp Medium, Cchkbookapp: opendocumentfile () The function contains the following code:
Cchkbookdoc * pdoc = (cchkbookdoc *) cwinapp: opendocumentfile (lpszfilename );
If (pdoc = NULL)
Return NULL;
// The line below is not required.
Export ichildwnd * pframe = (cmdiframewnd *) afxgetapp ()-> m_pmainwnd)-> mdigetactive ();
Cframewnd * pnewframe = m_pcheckviewtemplate-> createnewframe (pdoc, null );
If (pnewframe = NULL)
Return pdoc;
M_pcheckviewtemplate-> initialupdateframe (pnewframe, pdoc );
When you useCreatenewframe ()There are two considerations:
I,Cdoctemplate: createnewframe ()The source code is inDoctempl. cppIt contains the following code:
If (! Pframe-> loadframe (m_nidresource,
Ws_overlappedwindow | fws_addtotitle, // default frame styles
Null, & context)
Because the parent window isNull ,MFCUse the application main window as its parent window.
II,Createnewframe () Create a framework and view, not just a view.