CDocument* CChkworkApp::CreateNewFrameViewDoc(CChkworkDocTemplate* pDocTemplate)
{
POSITION posDoc=pDocTemplate->GetFirstDocPosition();
CDocument* pDocument =NULL;
if(posDoc!=NULL){
pDocument =pDocTemplate->GetNextDoc(posDoc);
//To get the first view in the list of views: POSITION posView = pDocument ->GetFirstViewPosition();
CView* pFirstView = pDocument ->GetNextView(posView);
// This example uses CDocument::GetFirstViewPosition
// and GetNextView to repaint each view.
ASSERT(pFirstView !=NULL);
pFirstView ->GetParentFrame()->GetLastActivePopup()->BringWindowToTop();
return pDocument;
}
else{
pDocument =pDocTemplate->CreateNewDocument();
if (pDocument == NULL)
{
TRACE0("CDocTemplate::CreateNewDocument returned NULL.\n");
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
return NULL;
}
ASSERT_VALID(pDocument);
CString strTitle;
pDocTemplate->GetDocString(strTitle,CDocTemplate::windowTitle);
pDocument->SetTitle(strTitle);
BOOL bAutoDelete = pDocument->m_bAutoDelete;
pDocument->m_bAutoDelete = FALSE;   // don't destroy if something goes wrong
CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(pDocument, NULL);
pDocument->m_bAutoDelete = bAutoDelete;
if (pFrame == NULL)
{
AfxMessageBox(AFX_IDP_FAILED_TO_CREATE_DOC);
delete pDocument;       // explicit delete on error
return NULL;
}
ASSERT_VALID(pFrame);
pDocTemplate->InitialUpdateFrame(pFrame ,pDocument,TRUE);
pFrame->ShowWindow(SW_SHOWMAXIMIZED);
}
return pDocument ;
}

解决方案 »

  1.   

    thank for jiangsheng(蒋晟) :
      能写的更详细一点吗?CChkworkDocTemplate好象是你自己建立的,我不能看懂。
      
      

  2.   

    用你自己的也可以啊,我这个CChkworkDocTemplate是用来修改菜单的。
    1寻找当前文档模板是否已经有创建的文档,如果是,则激活文档所在框架
    2如果否,则建立新文档/视图/框架
    pDocument =pDocTemplate->CreateNewDocument();建立文档
    CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(pDocument, NULL);建立框架
    pDocTemplate->InitialUpdateFrame(pFrame ,pDocument,TRUE);初始化框架