CView::GetDocument
CDocument* GetDocument( ) const;Return ValueA pointer to the CDocument object associated with the view. NULL if the view is not attached to a document.
CDocument* GetDocument( ) const;Return ValueA pointer to the CDocument object associated with the view. NULL if the view is not attached to a document.
在应用程序类中定义: CMultiDocTemplate* m_pTemplate1;///模板1
CMultiDocTemplate* m_pTemplate2;////模板2
CNewTLView *m_tlview;///视1
CDrawView *m_DrawView;////视2
然后在应用程序的BOOL CNewTLApp::InitInstance()函数中添加:
m_pTemplate1 = new CMultiDocTemplate(
IDR_NEWTLTYPE,
RUNTIME_CLASS(CNewTLDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDrawView));
m_pTemplate2 = new CMultiDocTemplate(
IDR_NEWTLTYPE,
RUNTIME_CLASS(CNewTLDoc),////////可以换成自己定义的文当类
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CDataListView))
以下是我在‘菜单’打开‘窗口’下‘WindowNew1’添加的代码
void CMainFrame::OnWindowNew1() CDocTemplate *pTemplate=((CNewTLApp *)AfxGetApp())->m_pTemplate1;
{
/////CNewTLApp 应用程序类
ASSERT_VALID(pTemplate);
CFrameWnd * pFrame=pTemplate->CreateNewFrame(pDocument,pActiveChild);
if(pFrame==NULL)
{
//TRACEO("warning:failed to creat.\n");
return;
}
pTemplate->InitialUpdateFrame(pFrame,pDocument);
}