m_pDocTemplate->OpenDocumentFile(NULL);//新文档
m_pDocTemplate->OpenDocumentFile(m_strFile);//打开文件
m_pDocTemplate为在CWinApp的文档模板指针

解决方案 »

  1.   

    不写OnFileNew()当然能生成,我想要OnFileNew(),所以要自己写了,
    注释是下面这个啊
    // TODO: Add your command handler code here
      

  2.   

    error C2039: 'm_pDocTemplate' : is not a member of 'CWinApp'
      

  3.   

    'CDocTemplate::OpenDocumentFile' : illegal call of non-static member function
      

  4.   

    就用系统默认的文档模板好了
    m_pDocTemplate = new CMultiDocTemplate(
    IDR_UABTYPE,
    RUNTIME_CLASS(CUABDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CUABView));
    //AddDocTemplate(pDocTemplate);
    AddDocTemplate(m_pDocTemplate);
      

  5.   

    就在 
    BOOL CAaApp::InitInstance()
    {
    CMultiDocTemplate* pDocTemplate;
    pDocTemplate = new CMultiDocTemplate(
    IDR_AATYPE,
    RUNTIME_CLASS(CAaDoc),
    RUNTIME_CLASS(CChildFrame), // custom MDI child frame
    RUNTIME_CLASS(CAaView));
    AddDocTemplate(pDocTemplate);}
    把CMultiDocTemplate* pDocTemplate;这句放在头文件让整个类都能用就行了
      

  6.   

    我自己找到CWinApp的原码片断如下:
    void CWinApp::OnFileNew()
    {
    if (m_pDocManager != NULL)
    m_pDocManager->OnFileNew();
    }
      

  7.   

    它这是调用CDocTemplate的方法,你按照我上面这种方法写,没问题的
      

  8.   

    POSITION l_position= AfxGetApp()->GetFirstDocTemplatePosition();
    CDocTemplate * l_pDoctemplate =AfxGetApp()->GetNextDocTemplate(l_position); l_pDoctemplate->CloseAllDocuments(FALSE); l_pDoctemplate->OpenDocumentFile();
         //openDocumentFile的参数为空时是新建。
         //也可以:       //m_pClassHtmlDocument是你的文档类。
    m_pClassHtmlDocument=l_pDocTemplate->CreateNewDocument();
    if(m_pClassHtmlDocument == NULL)
    return -1;
    CFrameWnd * l_pFrame = l_pDocTemplate->CreateNewFrame(m_pClassHtmlDocument,NULL);
    if(l_pFrame == NULL)
    return -1;
    l_pDocTemplate->InitialUpdateFrame(l_pFrame,m_pClassHtmlDocument);
      

  9.   

    CMainFrame::OnFileNew(){...}只在第一次打开新文档时执行,再打开一个就不执行,为什么?
    CMainFrame::OnFileClose(){...}根本不执行,为什么?
      

  10.   

    这个问题我知道,不过现在没时间,留个Email吧。
      

  11.   

    你在CMyApp里面重载它,这样可以直接用文档模板指针.明天我贴段代码给你把
      

  12.   

    已经可以了,这样:
    if (m_pDocManager != NULL)
        m_pDocManager->OnFileNew();另外:
    CMainFrame::OnFileNew(){...}只在第一次打开新文档时执行,再打开一个就不执行,为什么?
    CMainFrame::OnFileClose(){...}根本不执行,为什么?
      

  13.   

    to : cctime()
    源码以给你发出,没有用到onFieNew().