VC 编辑框显示打开文档内容的代码?? 我现在正在做一个基于对话框的界面,碰到了一个难题,点击 打开文件按钮,显示txt文档不能够在编辑框内显示,更别说保存文档了,谁能帮我解决一下????最好给出源代码!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这个不外乎是读出TXT文档,将它的内容显示到EDIT中。并不是很难,楼主自己写吧 给你段代码吧: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中去就行了。 楼上正解,对于小文件完全可以,TXT文件大一点,可能会出现假死机的现象可以用多线程解决此类问题 如果只能一行的话,将上面的"\n",换成"\r\n"试试 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();} 将EDIT里的内容用GetDlgItemText读到m_strText里面,然后用WriteString写进去文件中不就行了。 那就以追加文件的方式写吧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();} 请教高手关于进程反注入的问题 const char*与char数组的区别? 如何创建CFONT ....参数太多了... 急求解答:关于postmessage!为什么我向记事本发送了一个字符键A却没反应?? 哪里可以免费下载到关于图像的资料? 再次发帖,关于PostMessage或者SendMessage发送ctrl组合按键的问题 怎样通过外部操作终止我程序中运行的线程呢 在win2000下 怎么使edit透明 菜鸟问题,急,在线等待,关于ShellExecute的问题 学习过程中的迷惑? VC++ 中InfoViewer无法显示 TileWindows 平铺FORMVIEW怎么用?
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中去就行了。
可以用多线程解决此类问题
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();
}
{
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();
}