Search code examples
c++mfccfiledialog

C++ MFC CFileDialog won't save


I created a MFC programm with a menu option to Save a file. When I click it it shows the CFileDialog and I can choose the location where I want to save my file. 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.


Solution

  • 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.