HOWTO: Create Additional Views with CreateNewFrame() FunctionLast reviewed: July 10, 1997Article ID: Q100993 |
The information in this article applies to:
SUMMARYThe CDocTemplate::CreateNewFrame() function creates additional views of a document in a multiple document interface (MDI) application written using the Microsoft Foundation Class Library. The prototype of the CreateNewFrame() function is as follows:
CFrameWnd * CDocTemplate::CreateNewFrame(CDocument *, CFrameWnd *)To call this function, specify a pointer to a CDocument object (the document for which the function will create a view) and a pointer to a frame window that has properties to duplicate. Typically, the second parameter of the function is NULL. When an application calls CreateNewFrame(), the function creates a new frame window and a view in the frame window. The frame window type and view type depend on the document template (CDocTemplate) associated with the document specified in the CreateNewFrame() call.
MORE INFORMATIONTo better understand how to use CreateNewFrame(), it might be useful to review two examples. The first example is the WINMDI.CPP file in the Microsoft Foundation Class Library source code. WINMDI.CPP defines the function CMIDFrameWnd::OnWindowNew() that calls CreateNewFrame() to add an additional frame and view for a specified document. The application calls OnWindowNew() each time the user selects New from the MDI application's Windows menu. The OnWindowNew() function contains two significant lines of code, as follows:
CFrameWnd * pFrame = pTemplate->CreateNewFrame(pDocument, pActiveChild); pTemplate->InitialUpdateFrame(pFrame, pDocument);This code creates and displays the new frame window and document view. The other example is the DOCMULTI.CPP file, also in the Microsoft Foundation Class Library source code. The CMultiDocTemplate::OpenDocumentFile() function includes the following code:
CFrameWnd * pFrame = CreateNewFrame(pDocument, NULL);Note that the second parameter is NULL because the design of the OpenDocumentFile() function assumes that the programmer is not interested in duplicating any of the other frames that contain views of this document. The CHKBOOK sample also demonstrates creating additional frames and views for documents. In CHKBOOK.CPP, the CChkBookApp::OpenDocumentFile() function includes the following code:
CChkBookDoc * pDoc = (CChkBookDoc*)CWinApp::OpenDocumentFile(lpszFileName); if (pDoc == NULL) return NULL; CMDIChildWnd * pframe = ((CMDIFrameWnd *)AfxGetApp()->m_pMainWnd)->MDIGetActive(); CFrameWnd * pNewFrame = m_pCheckViewTemplate->CreateNewFrame(pDoc, NULL); if (pNewFrame == NULL) return pDoc; m_pCheckViewTemplate->InitialUpdateFrame(pNewFrame, pDoc);Here are two points to consider when you use the CreateNewFrame():
|
Additional query words: change view
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |