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;
}
这个另一种方法方便多了,在此记录一下