简体   繁体   English

C ++ MFC CFileDialog无法保存

[英]C++ MFC CFileDialog won't save

I created a MFC programm with a menu option to Save a file. 我使用菜单选项“保存文件”创建了一个MFC程序。 When I click it it shows the CFileDialog and I can choose the location where I want to save my file. 当我单击它时,它显示CFileDialog,并且我可以选择要保存文件的位置。 When I Click save in the Dialog, it closes the dialog, but after that it does nothing. 当我单击对话框中的保存时,它关闭对话框,但是此后什么也不做。 AND it didn't save my file. 而且它没有保存我的文件。 What am I doing wrong? 我究竟做错了什么?

Here is the code 这是代码

CFileDialog *dlg = new CFileDialog(FALSE, L"dr", NULL, NULL,
                   L"Drawings (*.dr)|*.dr|"
                   L"All Files||");

bool result = dlg->DoModal();

if(result)
{
    MessageBox(0, dlg->GetPathName(), L"Draw", 0);
}

The bool result, is purely there to check if there is no problem/error. 布尔结果仅用于检查是否没有问题/错误。

The file save dialog is called "file save dialog" because its caption says "Save File" and it allows you to only select a single file. 文件保存对话框之所以称为“文件保存对话框”,是因为其标题为“保存文件”,并且您只能选择一个文件。 That does not mean that it actually does any saving of files. 这并不意味着它实际上会保存任何文件。 It just returns to you the filename selected by the user. 它只是返回给您用户选择的文件名。 You are still responsible for writing the code which will save your file using this filename. 您仍然有责任编写代码,以使用该文件名保存文件。

The CFileDialog does not save the file for you, it only provides you with a dialog for the user to determine where (and if!) the file should be saved. CFileDialog不会为您保存文件,它只是为您提供一个对话框,供用户确定应将文件保存在何处(以及是否保存!)。 The return value of DoModal() should be compared to IDOK before proceeding to save. 在继续保存之前,应将DoModal()的返回值与IDOK比较。 From the dialog's member functions you can get the path and filename the user selected. 从对话框的成员函数中,您可以获取用户选择的路径和文件名。 With that, you can create/open a file and save your data. 这样,您可以创建/打开文件并保存数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM