各位大虾~~小弟是打算这样子的:打开一个选择文件对话框,选了几个文件之后,后台打开文件,处理完后,自动关闭文件。
代码如下所示。
但是在下面的while循环中,调用了一次OnCloseDocument()之后再次循环调OnOpenDocument()就会出现错误:
Unhandled exception in CoinRecognize.exe:0xC0000005:Accesse Violation. 我单步调试,发现OnOpenDocument()并没有进入意料中的函数,而是跳到了_AFX_INLINE CString::operator LPCTSTR() const
{ return m_pchData; }程序代码:
void CCoinRecognizeDoc::OnReadTFiles() 
{
CString str;   
CStdioFile file; 
CString temps;         //为了调用view中的函数
POSITION POS=GetFirstViewPosition();   
CCoinRecognizeView* pView= (CCoinRecognizeView*)GetNextView(POS);   CFileDialog fd(TRUE,NULL,NULL,OFN_ALLOWMULTISELECT,"BMP Files(*.bmp)|*.bmp");   
fd.DoModal();   
POSITION   filepos;   
filepos=fd.GetStartPosition();  
if(!file.Open("src.txt",CFile::modeCreate|CFile::modeWrite))return;  while(filepos!=NULL)   
{   
str=fd.GetNextPathName(filepos); 
 
OnOpenDocument(str); ///此处打开文档 ///*以下是自己的写的数据处理函数*//// pView-> OnOneKeyRht();
temps=formatData(pView->temp.x,pView->temp.y,pView->temp.radius);
file.WriteString(temps);                  //////////////////////////////////// OnCloseDocument();//此处关闭文档

} file.Close();
AfxMessageBox("succesed!");

}哪位大哥能告诉我个究竟啊……难道不可以这样关闭的么?
在线等……

解决方案 »

  1.   

    请看MSDN关于OnCloseDocument的说明,注意最后几句。
    CDocument::OnCloseDocument 
    virtual void OnCloseDocument( );ResCalled by the framework when the document is closed, typically as part of the File Close command. The default implementation of this function destroys all of the frames used for viewing the document, closes the view, cleans up the document's contents, and then calls the DeleteContents member function to delete the document’s data. 
      

  2.   

    试问document里面的内容都被清除了,怎么还能再成功执行document里的函数呢
      

  3.   

    自己重新OpenDocument和CloseDocument吧,不要和MFC framework 冲突
      

  4.   

    别用OpenDocument和CloseDocument
    再声明一个CFile fileRead
    专门用来读文件
      

  5.   

    自己处理文件操作,不要用MFC的那一套
      

  6.   

    结贴前:
    我还是自己写了自己的OpenDocument和CloseDocument函数……
    谢谢各位的参与……
    膜拜,离场……