我建立了一个view,一个doc,然后创建了一个文档模板,我在mdi程序中新建的时候打开这个视,然后我往里添加一个对话框资源,这个对话框是从CFormView继承来的,我在对话框的类中如何午到那个模板中的view和doc的指针?多谢,解决再加分。
解决方案 »
- vc连接oracle异常信息:ORA 12154 TNS无法解析制定的连接标示符
- VC2005编译的MFC程序在另外一台电脑上不能运行,为什么?
- IdropTarget接口releaseStgMedium老出错
- 关于打印机spool容量的问题,拜托各位高手!!
- 绑定CImageList对象的CListCtrl对象怎样显示一个背景透明的图标
- 两个线程共用一个函数会出现问题吗?
- 请教如何将多张静态图转成一张GIF动态图的方法
- 請問同時定義 extern CDVMApp theApp ; CDVMApp theApp; 是什麼用意?
- vc调用存储过程sp_who2,怎样加判断条件,搜索出想要的记录
- 关于转换视的基类的问题
- 散分没商量3
- 《vc++技术内幕》一书,第五版和第四版有什么区别?
CRuntimeClass* pNewViewClass;
pNewViewClass= RUNTIME_CLASS(CFormSettingsView);
CNetObserverDoc* doc=(CNetObserverDoc*)GetDocument();
ASSERT(doc);
if (!doc->SwitchToView(pNewViewClass))
TRACE("SwitchToView failed !!!\n");
else
TRACE("SwitchToView successful !!!\n");BOOL CNetObserverDoc::SwitchToView(CRuntimeClass *pNewViewClass)
{
int row, col;
row=0;col=1;
CMDIFrameWnd* pMainWnd = (CMDIFrameWnd*)AfxGetMainWnd();
// Get the active MDI child window.
CMDIChildWnd* pChild = (CMDIChildWnd*)pMainWnd->MDIGetActive();
// Get the active view attached to the active MDI child window.
CView* pOldActiveView = pChild->GetActiveView();
CSplitterWnd* pSplitter = (CSplitterWnd *)pOldActiveView->GetParent();
// ASSERT(pSplitter->IsChildPane(pOldActiveView, row, col));
pOldActiveView=(CView*)pSplitter->GetPane(row,col);
// If we're already displaying this kind of view, no need to go further.
if (pOldActiveView->IsKindOf(pNewViewClass))
return TRUE;
CRect viewrect;
pOldActiveView->GetWindowRect(&viewrect); // set flag so that document will not be deleted when view is destroyed
m_bAutoDelete = FALSE;
// Delete existing view
pOldActiveView->DestroyWindow();
// pOldActiveView->
m_bAutoDelete=TRUE;
// set flag back to default
// Create new view
CCreateContext context;
context.m_pNewViewClass = pNewViewClass;
context.m_pCurrentDoc = this;// POSITION pos=::AfxGetApp()->GetFirstDocTemplatePosition();
context.m_pNewDocTemplate =this->GetDocTemplate();// ::AfxGetApp()->GetNextDocTemplate(pos);
context.m_pLastView = NULL;
context.m_pCurrentFrame = NULL;
if (!pSplitter->CreateView(row, col, pNewViewClass, viewrect.Size(),
&context))
return FALSE;
CView* pNewView = (CView *)pSplitter->GetPane(row, col);
pNewView->OnInitialUpdate();
// Set active pSplitter->GetParentFrame()->SetActiveView(pNewView);
pSplitter->RecalcLayout();
pNewView->SendMessage(WM_PAINT);
return TRUE;
}
在Form视图中得到文档:CNetObserverDoc *pNDoc=(CNetObserverDoc *)GetDocument();
CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;// Get the active MDI child window.
CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame();
CMyView *pView = (CMyView *) pChild->GetActiveView();在构造对话框时将这个指针传递给对话框。如CMyDialog dlg(pView);