多文档模板的解决
CChildFrame* pFrame = new CChildFrame();
CCreateContext context;
context.m_pCurrentDoc=mp_doc; //that's the way I avoid to create new document every time I open a new view
context.m_pNewViewClass=RUNTIME_CLASS(CMulView);
context.m_pNewDocTemplate=pDocTemplate;
context.m_pLastView=(((CMainFrame *)m_pMainWnd)->GetActiveFrame() ? ((CMainFrame *)m_pMainWnd)->GetActiveFrame()->GetActiveView() : NULL);
context.m_pCurrentFrame=((CMainFrame *)m_pMainWnd)->GetActiveFrame();
if (!pFrame->LoadFrame(IDR_MULTYPE,WS_OVERLAPPEDWINDOW | FWS_PREFIXTITLE ,m_pMainWnd, &context ))return;
pFrame->InitialUpdateFrame(mp_doc,TRUE);
我用了2个模板,pDocTemplate这个是第一个模板变量,我在上面已经创建了模板,用了一个菜单函数,
为什么我第一次打开的时候没有问题,当关闭这个窗口后,就出现错误呢?????
问题点数:20、回复次数:3Top
1 楼masterz(www.fruitfruit.com)回复于 2005-08-18 13:58:05 得分 0
Here is my code to create multiple view for current document
void CdcmviewerDoc::OnViewHistogram()
{
if(m_dataset.size()>0 && m_rows>0 && m_cols>0)
{
CMainFrame* pframe = (CMainFrame*)AfxGetMainWnd();
pframe->CreateOrActivateFrame(((CdcmviewerApp*)AfxGetApp())->m_pHistDocTemplate,RUNTIME_CLASS(HistogramView));
CChildFrame* pMDIActive = (CChildFrame*)pframe->MDIGetActive();
HistogramView *pview = (HistogramView*)pMDIActive->GetActiveView();
pview->m_rows = m_rows;
pview->m_cols = m_cols;
pview->m_bits_stored = m_bits_stored;
pview->m_signed_image = m_signed_image;
pview->m_frame_index = m_frame_index;
CString title;
title.Format(_T("Histogram:%s"),pMDIActive->GetActiveDocument()->GetTitle());
pMDIActive->SetTitle(title);
}
}Top
2 楼masterz(www.fruitfruit.com)回复于 2005-08-18 13:58:32 得分 20
void CMainFrame::CreateOrActivateFrame(CDocTemplate* pTemplate,CRuntimeClass* pViewClass)
///////////////////////////////////////
// pDocumentTemplate is a CDocTemplate* to the template you wish to use
// which is passed into this function.
// pViewClass is a CRuntimeClass* to the view class desired which is
// passed into the function
{
// Get the currently active child.
CMDIChildWnd* pMDIActive = MDIGetActive();
ASSERT(pMDIActive != NULL);
if(pMDIActive == NULL)
return;
// now get that child's document... you may not need to do this, but if there may
// be multiple documents this a way to make sure that the correct set of windows
// is being acted on.
CDocument* pDoc = pMDIActive->GetActiveDocument();
ASSERT(pDoc != NULL);
CView* pView;
POSITION pos = pDoc->GetFirstViewPosition();
while (pos != NULL)
{
pView=pDoc->GetNextView(pos);
if(pView->IsKindOf(pViewClass))
{ // We found a view for this alreadycreated.
pView->GetParentFrame()->ActivateFrame();
return;
}
}
// This view doesn't exist for this document, create it
CMDIChildWnd* pNewFrame = (CMDIChildWnd*)(pTemplate->CreateNewFrame(pDoc, NULL));
if (pNewFrame ==NULL)
return; // not created you may want to assert here
ASSERT_KINDOF(CMDIChildWnd,pNewFrame);pTemplate->InitialUpdateFrame(pNewFrame, pDoc);
}Top
3 楼liuduofu(天上不下雨,地上也不干!)回复于 2005-08-18 16:58:22 得分 0
搞定,谢谢 masterz(www.fruitfruit.com) ( )!不过用对话框当子窗口这个还是没有搞定!!!!!!Top




