打开文件另存为操作

voidCTestdia1Doc::OnFileSaveAs()
{
// TODO: Add your command handler code here
CFileDialog dlg(TRUE);//<-
其中TRUE是“打开”对话框 FALSE是“另存为”对话框
int ret=dlg.DoModal();
if(ret==IDOK)
{
CString pathname=dlg.GetPathName();
CString filename=dlg.GetFileName();
char tbuf[120];
sprintf(tbuf,"The%s file in %s is saved!",filename,pathname); 

AfxMessageBox(tbuf);  以弹出对话框形式输出字符串信息
}
}

可以显示打开文件和文件另存为,并将选中的文件和文件名输出。

 

int sprintf( char *buffer, const char *format,[ argument] … );

函数是字串格式化命令,主要功能是把格式化的数据写入某个字符串中。

你可能感兴趣的:(mfc,对话框)