程序的流程是这样的:
1.在对话框中动态创建按钮
2.按钮中的响应事件是创建一个窗口(继承自CFrameWnd)
3.在窗口中加入一个视图,视图是继承自CFormView
其中(1)、(2)项都已解决了,问题出在(3)项中,我是在CMyFrameWnd::OnCreateClient中用如下语句创建视图的,但是出错了,不知道何解???
CRuntimeClass* pNewViewClass;
pNewViewClass = RUNTIME_CLASS(CMyForm);
pContext.m_pNewViewClass = pNewViewClass;
出错的提示:
error C2065: 'IDD_MYFORMVIEW' : undeclared identifier   (IDD_MYFORMVIEW是资源,我明明在Dialog中创建了,真奇怪)
error C2057: expected constant expression
error C2228: left of '.m_pNewViewClass' must have class/struct/union type Error executing cl.exe.或者要实现第三步,哪位大哥有代码了,谢谢!!!!main.exe - 3 error(s), 0 warning(s)

解决方案 »

  1.   


    IDR_MAINFRAME 这个资源一定要有, 菜单 工具条之类的,
    CYourDoc
    CMainFrame       
    CYourView  
    一定要作好,也可以从别的项目拷贝过来
     
    CYourApp::InitInstance()
    {
        ...
        SetRegistryKey(_T("应用程序向导生成的本地应用程序"));    // 添加下面的代码 , 可以从别的项目拷贝过来    CSingleDocTemplate* pDocTemplate;
            pDocTemplate = new CSingleDocTemplate(
            IDR_MAINFRAME,                           // 注意这个资源要有 菜单。
            RUNTIME_CLASS(CYourDoc),
            RUNTIME_CLASS(CMainFrame),       
            RUNTIME_CLASS(CYourView));
        if (!pDocTemplate)
            return FALSE;
        AddDocTemplate(pDocTemplate);
     
        ......
    }// 在单击消息里添加代码
    void CYourDlg::OnBnClickedButton1()
    {
        CCommandLineInfo cmdInfo;
        AfxGetApp() -> ParseCommandLine(cmdInfo);    
        if (!AfxGetApp() -> ProcessShellCommand(cmdInfo))
            return ;
        AfxGetApp() -> m_pMainWnd -> ShowWindow (SW_SHOW) ;
        AfxGetApp() -> m_pMainWnd -> UpdateWindow () ;
    }你的对话框 关闭时 m_pMainWnd 也将关闭。我认为还是应该 建立一个 DOC/View 项目 ,
    然后在m_pMainWnd -> ShowWindow (SW_SHOW) ;
    之前显示一个对话框,比较自然。
      

  2.   

    可以 尝试 这样的代码(如果 错了 我不负责)
    pDocTemplate = new CMultiDocTemplate(IDR_ABC4TYPE,
    RUNTIME_CLASS(CABC4Doc),
    RUNTIME_CLASS(CMyFrame), // 自定义 MDI 子框架
    RUNTIME_CLASS(CABC4View));
    if (!pDocTemplate)
    {
    MessageBox ("Error!  -----Create DocTemplate !") ;
    return ;
    }
    m_pDoc = (CABC4Doc*) pDocTemplate -> CreateNewDocument () ;
    if ( !m_pDoc) return ;
    m_pMyFrame = (CMyFrame*) pDocTemplate -> CreateNewFrame (m_pDoc, this) ;
    if ( !m_pMyFrame) return ;
    m_pMyFrame -> ShowWindow (SW_SHOW) ;
    m_pMyFrame -> UpdateWindow () ;
      

  3.   

    RUNTIME_CLASS(CMyFrame), // 自定义 MDI 子框架
    这个注释 是从 vc 自动生成的代码 拷贝 时带上去的, CMyFrame 是自己定义的 
    从CFrameWnd 继承
      

  4.   

    唉,问题还是自己解决了!!!!
    加上include "resource.h"就行了斑主给我结贴吧!!!
    我的分数要回来呀!!