How to Use the createnewframe () function to create other views

Source: Internet
Author: User

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.

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.