BOOL CFileCWtestDlg::OnInitDialog()
{
// TODO: 在此添加额外的初始化代码
GetSystemTime();
}
void CFileCWtestDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CString filename;
GetDlgItemText(IDC_STATIC_FileDir,filename);
CStdioFile file;
file.Open(filename, CFile::modeCreate);
MessageBox(filename+_T("文件创建成功"),"信息提示",MB_OK);
}
void CFileCWtestDlg::GetSystemTime()
{
CString StrCurTime;
SYSTEMTIME SysTime;
::GetLocalTime(&SysTime);
StrCurTime.Format (_T("C:\\%d-%d-%d.txt"),SysTime.wYear,SysTime.wMonth,SysTime.wDay);
SetDlgItemText(IDC_STATIC_FileDir,StrCurTime);
}
void CFileCWtestDlg::OnBnClickedButton2()
{
// TODO: 在此添加控件通知处理程序代码
CString filename,strTmp;
GetDlgItemText(IDC_STATIC_FileDir,filename);
GetDlgItemText(IDC_EDIT1,strTmp);
CStdioFile file;
file.Open(filename,CFile::modeWrite);
file.SeekToEnd();//打开文件,文件指针是在起始位置,你写入就会覆盖,写之前先调用file.SeekToEnd
file.WriteString(strTmp);
file.Close();
}
http://download.csdn.net/detail/bbsview/4549333点击打开下载链接