Do not re-open the MFC multi-document approach

    template<typename T>
    inline CView* GetView(CDocument* pDoc)
    {
	    CView* pView;
    	POSITION pos = pDoc->GetFirstViewPosition();
	    CRuntimeClass* pClass = RUNTIME_CLASS(T);

    	while (pos != NULL) {
	    	pView = pDoc->GetNextView(pos);
		    if (!pView->IsKindOf(pClass))
			    break;
    	}

	    if (!pView->IsKindOf(pClass)) {
		    return NULL;
    	}

	    return pView;
    }


     CView* pView = nullptr;
	 POSITION pos = theApp.GetMeterReportT()->GetFirstDocPosition();
	 while (pos)
	 {
		 CDocument* pDoc = theApp.GetMeterReportT()->GetNextDoc(pos);
		 if (pDoc->IsKindOf(RUNTIME_CLASS(CNaturalMeterDoc)))
		 {
			 pView = GetView<CMeterReportView>(pDoc);
			 if (pView)
			 {
				 pView->GetParentFrame()->ActivateFrame();
				 break;
			 }
		 }

	 }

	 if (nullptr == pView)
	 {
		 theApp.GetMeterReportT()->OpenDocumentFile(nullptr);
	 }

CMultiDocTemplate * CxxxxxApp :: GetMeterReportT () const // flow statement template 
{
    return m_pMeterReportT;
}

This alternative method more convenient, look at this record

Published 14 original articles · won praise 0 · Views 9847

Guess you like

Origin blog.csdn.net/u011512808/article/details/104720207