VC CFile Open save
2012-06-05 20:29
106 查看
void CCh7Demo4Dlg::OnSave()
{
// TODO: Add your control notification handler code here
char szName[40];
CString strFilter,strFileName,strText;
strFilter = "BOOKINFO Files(*.*)|*.*||";
CFileDialog dlg(FALSE,NULL, NULL, OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_FILEMUSTEXIST, strFilter);
if(dlg.DoModal() == IDOK)
{
strFileName = dlg.GetPathName();
CFile m_file(strFileName,CFile::modeCreate|CFile::modeWrite);
if(m_list.GetCount() == 0)
{
AfxMessageBox("Data empty");
return ;
}
for(int i = 0;i < m_list.GetCount(); i++)
{
m_list.GetText(i, strText);
strcpy(szName, strText);
m_file.Write(&szName,sizeof(szName));
}
m_file.Close();
}
}
void CCh7Demo4Dlg::OnOpen()
{
// TODO: Add your control notification handler code here
CString strFilter, strFileName;
char szName[40];
strFilter = "BOOKINFO Files(*.*)|*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_FILEMUSTEXIST, strFilter);
if(dlg.DoModal() == IDOK)
{
int nvalue = MessageBox("Now Data not save will lost,continue?", "Info",4+32+256);
if(nvalue == 6)
{
m_list.ResetContent();
CString fileName = dlg.GetPathName();
CFile m_file(fileName,CFile::modeRead);
int i = 0;
m_file.SeekToBegin();
while(m_file.Read(&szName,sizeof(szName)) != 0)
{
m_list.AddString((CString)szName);
}
m_file.Close();
}
else
{
return ;
}
}
}
{
// TODO: Add your control notification handler code here
char szName[40];
CString strFilter,strFileName,strText;
strFilter = "BOOKINFO Files(*.*)|*.*||";
CFileDialog dlg(FALSE,NULL, NULL, OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_FILEMUSTEXIST, strFilter);
if(dlg.DoModal() == IDOK)
{
strFileName = dlg.GetPathName();
CFile m_file(strFileName,CFile::modeCreate|CFile::modeWrite);
if(m_list.GetCount() == 0)
{
AfxMessageBox("Data empty");
return ;
}
for(int i = 0;i < m_list.GetCount(); i++)
{
m_list.GetText(i, strText);
strcpy(szName, strText);
m_file.Write(&szName,sizeof(szName));
}
m_file.Close();
}
}
void CCh7Demo4Dlg::OnOpen()
{
// TODO: Add your control notification handler code here
CString strFilter, strFileName;
char szName[40];
strFilter = "BOOKINFO Files(*.*)|*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_EXPLORER|OFN_HIDEREADONLY|OFN_ENABLESIZING|OFN_FILEMUSTEXIST, strFilter);
if(dlg.DoModal() == IDOK)
{
int nvalue = MessageBox("Now Data not save will lost,continue?", "Info",4+32+256);
if(nvalue == 6)
{
m_list.ResetContent();
CString fileName = dlg.GetPathName();
CFile m_file(fileName,CFile::modeRead);
int i = 0;
m_file.SeekToBegin();
while(m_file.Read(&szName,sizeof(szName)) != 0)
{
m_list.AddString((CString)szName);
}
m_file.Close();
}
else
{
return ;
}
}
}
相关文章推荐
- VC下使用CFile 的OPEN函数路径问题
- C#对话框(OpenFileDialog、SaveFileDialog 、ColorDialog、FontDialog)
- OpenFileDialog、SaveFileDialog常用属性、对话框用法
- VC2010 C++ error C1083: Cannot open include file: 'XXXXX.h': No such file or directory
- CFile f; CFileException e; if(!f.Open(pFileName,CFile::modeRead...
- VC:注册表:查询、删除项(CRegKey 的方法:Open、QueryValue、.DeleteValue、DeleteSubKey、RecurseDeleteKey)
- fatal error LNK1104: cannot open file 'libboost_system-vc90-mt-s-1_xx.lib'
- open-vcdiff流式编码过程分析(二)
- Silverlight 5 RC新特性探索系列:11.SaveFileDialog保存文件指定默认名称---OpenFileDialog打开文件指定默认路径
- Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space.
- 设置savepanel或openpanel的默认打开路径方法
- Windows 8 文件选择器(FileOpenPicker,FileSavePicker,FolderPicker)
- Some of the best Open Source Project's in VC++ & MFC
- CFile::open函数不能以CFile::typeText方式打开文件
- 豁然开朗:解决cant open "stlport_vc6_static.lib"(二)
- Some of the best Open Source Project's in VC++ & MFC
- VC编译时出现 cannot open file '.'.\Debug\Test1.sbr': No such file or directory 怎么关闭Browser Info
- 创建一个如下的窗体,并在窗体上放置saveFileDialog、openFileDialog两个控件。
- 关于OpenFileDialog与SaveFileDialog的错误
- Using OpenAPI with C++[1] _VC调用WebService