void CTestDlg::OnOpen()
{
// TODO: Add your control notification handler code here
//bOpenFileDialog(TRUE):'打开'对话框
//lpszDefExt:扩展名
//lpszFileName:文件名称
//dwFlags:自定义文件对话框
//lpszFilte:用于指定对话框过滤的文件类型(文件类型说明和扩展名间用"|"分隔,每种文件类型间用"|"分隔,末尾用"||"结束.)
//pParentWnd:标识文件对话框的父窗口指针
//CFileDialog dlg(TRUE, NULL, NULL, NULL, NULL, NULL);
CFileDialog dlg(TRUE);
CString strPath, strText = "";
if(dlg.DoModal()==IDOK)
{
strPath = dlg.GetPathName();
SetDlgItemText(IDC_STATIC1, strPath);
CFile file(strPath, CFile::modeRead);
char read[10000];
file.Read(read, 10000);
for(int i=0;i<file.GetLength();i++)
{
strText+=read[i];
}
file.Close();
SetDlgItemText(IDC_EDIT1, strText);
}
}
void CTestDlg::OnSave()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(FALSE);
CString strPath, strText="";
char write[10000];
if(dlg.DoModal()==IDOK)
{
strPath = dlg.GetPathName();
if(strPath.Right(4)!=".TXT")
strPath += ".TXT";
SetDlgItemText(IDC_STATIC2, strPath);
CFile file(_T(strPath), CFile::modeCreate|CFile::modeWrite);
GetDlgItemText(IDC_EDIT1, strText);
strcpy(write, strText);
file.Write(write,strText.GetLength());
file.Close();
}
}
原文链接: https://www.cnblogs.com/pythonschool/archive/2012/11/21/2773648.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/70148
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!