这样的文档、框架、视图的问题,肯定都是老生长谈了,我们都知道文档和视图的关系是一对多关系。也做很久的项目了,可是还有些疑问没有解决。请各位DX讨论指点下。程序基本情况:MDI程序架构,一个文档对应多个视图。比如:CMyApp --> CMyDocument -->(CChartView/CChildFrme + CListView/CChildFrme + CFormView/CChildFrme ...),每个文档对应的视图有多个,每一类视图都有自己的菜单和工具栏。那么对于这样的实现,比较经典的做法是如何的?特开此贴总结一下以享各位朋友。假设Class有:
CMyApp
CMainFrame
CMyDocuemnt
CChartView
CListView
CFormView
CChildFrame1
CChildFrame2
CChildFrame3我对于多种视图的创建一般都是采用context,以及CChildFrame的LoadFrame来做。 CCreateContext context;
//CMyChildFrame* pMyChildFrame = new CMyChildFrame();
CRuntimeClass* pFrameClass = RUNTIME_CLASS(CMyChildFrame);
CMyChildFrame* pMyChildFrame =(CMyChildFrame*) pFrameClass->CreateObject();
context.m_pNewViewClass = RUNTIME_CLASS(CMyTestView); pMyChildFrame->LoadFrame(IDI_ICON1,WS_OVERLAPPEDWINDOW|FWS_ADDTOTITLE,this,&context); pMyChildFrame->InitialUpdateFrame(NULL,TRUE); 可对于菜单、工具栏切换我就不熟悉了。请各位DX稍微详细给出你的方法和示例代码,谢谢了!
CMyApp
CMainFrame
CMyDocuemnt
CChartView
CListView
CFormView
CChildFrame1
CChildFrame2
CChildFrame3我对于多种视图的创建一般都是采用context,以及CChildFrame的LoadFrame来做。 CCreateContext context;
//CMyChildFrame* pMyChildFrame = new CMyChildFrame();
CRuntimeClass* pFrameClass = RUNTIME_CLASS(CMyChildFrame);
CMyChildFrame* pMyChildFrame =(CMyChildFrame*) pFrameClass->CreateObject();
context.m_pNewViewClass = RUNTIME_CLASS(CMyTestView); pMyChildFrame->LoadFrame(IDI_ICON1,WS_OVERLAPPEDWINDOW|FWS_ADDTOTITLE,this,&context); pMyChildFrame->InitialUpdateFrame(NULL,TRUE); 可对于菜单、工具栏切换我就不熟悉了。请各位DX稍微详细给出你的方法和示例代码,谢谢了!
{
/*
Parameters
bActivate
Indicates whether the view is being activated or deactivated. pActivateView
Points to the view object that is being activated. pDeactiveView
Points to the view object that is being deactivated. */
// TODO: Add your specialized code here and/or call the base class
if (bActivate)
{
((CMDIAppDemoDoc*)GetDocument())->m_hMyMenu = ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MDIAppDemoTYPE));
CMainFrame* pMain = (CMainFrame*) AfxGetMainWnd();
if (pMain)
{
pMain->OnUpdateFrameMenu(NULL);
pMain->DrawMenuBar();
}
} CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
比较关注的就是各位dX都是如何控制MDI框架下一个文档对应的多视图的创建呢?
{
return m_hMyMenu; // just use original default
}