我现在正在做一个基于对话框的界面,碰到了一个难题,点击 打开文件按钮,显示txt文档不能够在编辑框内显示,更别说保存文档了,谁能帮我解决一下????最好给出源代码!!

解决方案 »

  1.   

    这个不外乎是读出TXT文档,将它的内容显示到EDIT中。并不是很难,楼主自己写吧
      

  2.   

    给你段代码吧:
    CStdioFile m_readfile;  
    CString m_strTemp;
    m_readfile.Open( "1.txt ",CFile::modeRead);  
    m_strTemp.Empty();
    m_strText.Empty();
    while(m_readfile.ReadString(m_strTemp))
    {  
    m_strText+=m_strTemp+ "\n ";  
    }
    此时,TXT文件的内容已经读到了m_strText中了
    然后用SetDlgItemText将m_strText中的内容显示到EDIT中去就行了。
      

  3.   

    楼上正解,对于小文件完全可以,TXT文件大一点,可能会出现假死机的现象
    可以用多线程解决此类问题
      

  4.   

    如果只能一行的话,将上面的"\n",换成"\r\n"试试
      

  5.   


    try
    {
     CStdioFile file;
     CString strText(_T(""));
     GetDlgItemText(IDC_EDIT1, strText);
     file.Open(_T("F:\\11.txt"), CFile::modeCreate|CFile::modeReadWrite);
     file.WriteString(strText);
     file.Close();
    }
    catch(CFileException* e)
    {
     e->ReportError();
     e->Delete();
    }
      

  6.   

    将EDIT里的内容用GetDlgItemText读到m_strText里面,然后用WriteString写进去文件中不就行了。
      

  7.   

    那就以追加文件的方式写吧try
    {
     CStdioFile file;
     CString strText(_T(""));
     GetDlgItemText(IDC_EDIT1, strText);
     file.Open(_T("F:\\11.txt"), CFile::modeCreate|CFile::modeReadWrite|CFile::modeNoTruncate);
     file.SeekToEnd();
     file.WriteString(strText);
     file.Close();
    }
    catch(CFileException* e)
    {
     e->ReportError();
     e->Delete();
    }