MFC 多文档禁止重复打开的方法

    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          //流量报表模板 
{
    return m_pMeterReportT;
}

这个另一种方法方便多了,在此记录一下

发布了14 篇原创文章 · 获赞 0 · 访问量 9847

猜你喜欢

转载自blog.csdn.net/u011512808/article/details/104720207
MFC
今日推荐