(1)在MFC中的多文档工程中得到当前文档
CMDIFrameWnd  *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; 
CMDIChildWnd  *pChild = (CMDIChildWnd   *)pFrame->GetActiveFrame();   
CView   *pV = (CView*)pChild->GetActiveView();
CDocument* pDoc = pV->GetDocument();
(2)在MFC中的多文档工程中遍历所有文档
POSITION pos = theApp.GetFirstDocTemplatePosition();
while (pos != NULL)
{
 CDocTemplate *p = theApp.GetNextDocTemplate(pos);
 POSITION posdoc = p->GetFirstDocPosition();
 while (posdoc != NULL)
 {
  CDocument* pDoc = p->GetNextDoc(posdoc);
       if (pDoc != NULL)
      {
           POSITION posview = pDoc->GetFirstViewPosition();
          if (posview != NULL)
          {
              CView* pV = pDoc->GetNextView(posview);
          }
      }
   }
}
(3)关闭某个文档

      pDoc->OnCloseDocument();

 posted on 2011-03-20 05:30  Jiang, X.  阅读(2119)  评论(0编辑  收藏  举报