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;
}
这个另一种方法方便多了,在此记录一下
标签:MFC,return,重复,pos,pView,GetMeterReportT,文档,theApp,pDoc 来源: https://blog.csdn.net/u011512808/article/details/104720207