我要创建多个视图,没个视图显示不同。比如点击不同菜单项,新建一个窗口,窗口显示的内容不同。
  请问怎么实现?也就是一个DOc,多个View,请详细说明。

解决方案 »

  1.   

    你的需求sdi就可以实现了,去找找 单文档多视图切换的例子,网上很多
      

  2.   

    典型的SDI。
    SDI和MDI区别就在于是否多个Doc
      

  3.   

    BCG里面有个BcgtabView可以满足你的需要
      

  4.   

    首先在~~App中声明CMultiDocTemplate* 指针,例如:
    class CJIANApp : public CWinApp
    {
    public:
    CJIANApp();
    CMultiDocTemplate* m_pDocTemplate;
            CMultiDocTemplate* pFirstTemplate;
    .........
    }
    接着在BOOL CJIANApp::InitInstance()中把原先的
            CMultiDocTemplate* m_pDocTemplate;
    m_pDocTemplate = new CMultiDocTemplate(
    IDR_JIANTYPE,
    RUNTIME_CLASS(CJIANDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CJIANView));
    AddDocTemplate(m_pDocTemplate);
    改为:
           m_pDocTemplate = new CMultiDocTemplate(
    IDR_JIANTYPE,
    RUNTIME_CLASS(CJIANDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CJIANView));
    AddDocTemplate(m_pDocTemplate); //Add an external Doctemplate pFirstTemplate = new CMultiDocTemplate(
    IDR_JIANTYPE,
    RUNTIME_CLASS(CJIANDoc),
    RUNTIME_CLASS(CFirstFrame), // 自己建立的以CMDIChildWnd为基类
    RUNTIME_CLASS(CJIANView1));// 自己建立的以~~View为基类由你决定
    //AddDocTemplate(pFirstTemplate);
    并且加上头文件:
    #include "MainFrm.h"
    #include "ChildFrm.h"
    #include "FirstFrame.h"
    #include "JIANDoc.h"
    #include "JIANView.h"
    #include "JIANView1.h"接着打开两个视图的代码:
    void CJIANView::OnInitialUpdate() 
    {
    CView::OnInitialUpdate();

    // TODO: Add your specialized code here and/or call the base class
    CJIANDoc *pDoc=GetDocument();
    ASSERT_VALID(pDoc);
    CMainFrame *pAppFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
    ASSERT_KINDOF(CMainFrame,pAppFrame);
    pDoc->pChildFrame=(CChildFrame *)GetParentFrame();
    CMultiDocTemplate *pFirstTemplate=((CJIANApp *)AfxGetApp())->pFirstTemplate; ASSERT_VALID(pFirstTemplate);
    pDoc->pFirstFrame=(CFirstFrame *)pFirstTemplate->CreateNewFrame(pDoc,pAppFrame);
    pFirstTemplate->InitialUpdateFrame(pDoc->pFirstFrame,pDoc);
    }
    //加上必要的头文件是不可少的
    #include "JIANDoc.h"
    #include "JIANView.h"
    #include "JIANView1.h"
    #include "MainFrm.h"
    //用来打开另外的一个视图
    void CJIANView::OpenCodeList()
    {
        CJIANDoc *pDoc=GetDocument();
        if(pDoc->haveclose==0){
    POSITION pos;
    pos=pDoc->GetFirstViewPosition();
    CView * pView;
    while(pos!=NULL){
    pView=pDoc->GetNextView(pos);
    if(pView->IsKindOf(RUNTIME_CLASS(CJIANView1))){ 
    pView->GetParentFrame()->ActivateFrame();
    return;
    }
    }
    }
    ASSERT_VALID(pDoc);
    CMainFrame *pAppFrame=(CMainFrame *)AfxGetApp()->m_pMainWnd;
    CMultiDocTemplate *pFirstTemplate=((CJIANApp *)AfxGetApp())->pFirstTemplate;
    pDoc->pFirstFrame=(CFirstFrame *)pFirstTemplate->CreateNewFrame                         (pDoc,pAppFrame);
    pFirstTemplate->InitialUpdateFrame(pDoc->pFirstFrame,pDoc);

    pDoc->haveclose=0;
    }class CJIANDoc : public CDocument
    {
    protected: // create from serialization only
    CJIANDoc();
    DECLARE_DYNCREATE(CJIANDoc)// Attributes
    public:
    CChildFrame *pChildFrame;
    CFirstFrame *pFirstFrame;
    }
    并且加上头文件 
    #include "ChildFrm.h"
    #include "FirstFrame.h"
    ////////用CJIANView1视图时打开CJIANView视图
    void CJIANView1::OpenMapList()
    {
    CJIANDoc *pDoc=(CJIANDoc *)GetDocument();
        
    POSITION pos;
    pos=pDoc->GetFirstViewPosition();
    CView * pView;
    while(pos!=NULL){
    pView=pDoc->GetNextView(pos);
    if(!pView->IsKindOf(RUNTIME_CLASS(CJIANView1))){ 
    pView->GetParentFrame()->ActivateFrame();
    return;
    }
    }
    }
      

  5.   

    dengxuxing:
      你的代码中FirstFrame和JIANView1,都是怎么得来的啊?自己建的继承childframe和view类?