一个文档,多个视,不能获得文档指针
一个文档,多个视,不能获得文档指针。
在BOOL CEmluator200App::InitInstance()中:
m_pCpuViewTemplate= new CMultiDocTemplate(IDR_CPUFRAME,
RUNTIME_CLASS(CEmluator200Doc),------!
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CCpuView));
AddDocTemplate(m_pCpuViewTemplate);
m_pIbViewTemplate= new CMultiDocTemplate(IDR_IBFRAME,
RUNTIME_CLASS(CEmluator200Doc),------!
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CIbView));
AddDocTemplate(m_pIbViewTemplate);
在void CEmluator200App::OnFileNew() 中:
CFrameWnd* pNewFrame = m_pCpuViewTemplate->CreateNewFrame(NULL, NULL);
if (pNewFrame == NULL)
return ;
m_pCpuViewTemplate->InitialUpdateFrame(pNewFrame, NULL);
// Tile the two MDI children windows within the MDI frame window.
ASSERT_KINDOF(CMDIChildWnd, pNewFrame);
CMDIFrameWnd* pMDIFrameWnd = ((CMDIChildWnd*)pNewFrame)->GetMDIFrame();
ASSERT(pMDIFrameWnd != NULL);
在void CMainFrame::OnIdleUpdateCmdUI()中:
CMDIChildWnd* pChild = MDIGetActive();
if ( pChild )
{
CView *pView = pChild->GetActiveView();
if ( pView )
{
CDocument* pDoc = pView->GetDocument();//MDIGetActive()->GetActiveView()->GetDocument()
ASSERT_VALID(pDoc);-------》》》!!为空
if ( pDoc )
{
CDocTemplate* pDocTemplate = pDoc->GetDocTemplate();
if ( pDocTemplate )
{
// Class to extract the m_nIDResource member
class CHelperDocTemplate : public CDocTemplate
{
public:
CHelperDocTemplate():CDocTemplate(0,
NULL, NULL, NULL){}
UINT GetResourceId(){return m_nIDResource;}
};
CHelperDocTemplate* pHelper = (
CHelperDocTemplate*) pDocTemplate;
UINT n = pHelper->GetResourceId();
if ( SelectToolBar(IDR_CPUFRAME) ) return;
}
}
}
}
在Cpuview中
CEmluator200Doc* GetDocument()
{
// ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEmluator200Doc)));
return (CEmluator200Doc*) m_pDocument;
}
也不行。
试了不但在OnIdleUpdateCmdUI中不能获得,其他地方也不行。