保存文件时怎样设置CFileDialog默认文件名,要求文件名取当前的日期,是一变量
CFileDialog filedlg(false, "txt", "123.txt", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "bitmap file (*.txt) |*.txt| |");
filedlg.m_ofn.lpstrTitle = "保存文件";
filedlg.m_ofn.lpstrInitialDir = "e:\\";//初始路径
filedlg.m_ofn.nMaxFile = MAX_PATH;
if (filedlg.DoModal() == IDCANCEL)
return;
如果要求每一次保存都取当前日期的话,filedlg.m_ofn.lpstrTitle =tempfilename
tempfilename应该为变量,不知道为什么不行,要实现这个功能用什么方法呢?谢谢!
3 个解决方案
#1
CString strFile(COleDateTime::GetCurrentTime().Format("%Y-%m-%d.txt"));
CFileDialog filedlg(false,
"txt",
strFile,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "bitmap file (*.txt) |*.txt| |");
strFile="保存文件:"+strFile;
filedlg.m_ofn.lpstrTitle = strFile;
filedlg.m_ofn.lpstrInitialDir = "e:\\";//初始路径
filedlg.m_ofn.nMaxFile = MAX_PATH;
if (filedlg.DoModal() == IDCANCEL)
return;
CFileDialog filedlg(false,
"txt",
strFile,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "bitmap file (*.txt) |*.txt| |");
strFile="保存文件:"+strFile;
filedlg.m_ofn.lpstrTitle = strFile;
filedlg.m_ofn.lpstrInitialDir = "e:\\";//初始路径
filedlg.m_ofn.nMaxFile = MAX_PATH;
if (filedlg.DoModal() == IDCANCEL)
return;
#2
好
#3
测试过了吗?
#1
CString strFile(COleDateTime::GetCurrentTime().Format("%Y-%m-%d.txt"));
CFileDialog filedlg(false,
"txt",
strFile,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "bitmap file (*.txt) |*.txt| |");
strFile="保存文件:"+strFile;
filedlg.m_ofn.lpstrTitle = strFile;
filedlg.m_ofn.lpstrInitialDir = "e:\\";//初始路径
filedlg.m_ofn.nMaxFile = MAX_PATH;
if (filedlg.DoModal() == IDCANCEL)
return;
CFileDialog filedlg(false,
"txt",
strFile,
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "bitmap file (*.txt) |*.txt| |");
strFile="保存文件:"+strFile;
filedlg.m_ofn.lpstrTitle = strFile;
filedlg.m_ofn.lpstrInitialDir = "e:\\";//初始路径
filedlg.m_ofn.nMaxFile = MAX_PATH;
if (filedlg.DoModal() == IDCANCEL)
return;
#2
好
#3
测试过了吗?