比如继承了CEditView,但打开文件时只是在view上显示了文件名,但没有显示文件内容,这是怎么回事呢?用AfxGetApp()->OpenDocumentFile(filename)也没有效果:(

解决方案 »

  1.   

    你必须Serialize()中把文件读进来阿,你不读的话,他怎么知道你要呢?
      

  2.   

    在应用类里重载OnFileNew()函数,对文件进行读入处理。
      

  3.   

    在文档类的下面函数中,添加代码如下:
    void CTestSDIDoc::Serialize(CArchive& ar)
    {
    if (ar.IsStoring())
    {
    // TODO: add storing code here

    }
    else
    {
    // TODO: add loading code here
    CString str;//添加的代码
    ar>>str;//添加的代码
    }
    }
    然后用来打开一个文本文件,再debug一下,看看str中值的变化,你就明白了
    取得文件中的数据后,再取得视图的指针就可以在视中显示了。