Kent
Kent

Reputation: 1

Overwrite OnFileOpen and OnFileSave function - registry is not updated?

I have a little problem that I do not know how to solved:

I am writing a program that involves data serialization. I decided to override the OnFileOpen and OnFileSave function because I wanted to modify the File Dialog Box when open/save the file.

My problem is: after I load the file, the program title still remains 'Untitled' and the 'Recent File' list under the 'File' menu bar is not updated either.

I suppose I need to add some code to update the registry? But I struggle to find the solution of it...

Thank you all for the helps! Highly appreciated!

Here are my OnFileOpen and OnFileSave code:

void CXXXDoc::OnFileOpen()
{
    // TODO: Add your command handler code here

    TCHAR szFilters[]= _T("XXX Type Files (*.xxx)|*.xxx|All Files (*.*)|*.*||");
    CFileDialog fileDlg(TRUE, _T("xxx"), _T("*.xxx"), OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, szFilters);
    if(fileDlg.DoModal() == IDOK)
    {
        CFile oldFile;
        ASSERT (oldFile != NULL);
        oldFile.Open(fileDlg.GetPathName(), CFile::modeRead | CFile::shareExclusive);
        FilePathName = fileDlg.GetPathName();
        SetTitle(FilePathName);
        CArchive loadArchive(&oldFile, CArchive::load | CArchive::bNoFlushOnDelete); // Create the archive to load data, the archive must be closed manually after the loading process      
        Serialize(loadArchive);
        loadArchive.Close();
        oldFile.Close();        
        UpdateAllViews(0);

    }

}

void CXXXDoc::OnFileSave()
{
            CFile newfile;
        ASSERT (newfile != NULL);
        newfile.Open(FilePathName, CFile::modeWrite);
        CArchive saveArchive(&newfile, CArchive::store);   // Create the archive to save data,
        Serialize(saveArchive);
        saveArchive.Close();
        newfile.Close();
}

Upvotes: 0

Views: 1524

Answers (1)

Roger Rowland
Roger Rowland

Reputation: 26259

To keep the most recently used (MRU) list updated, you need to call CWinApp::AddToRecentFileList (MSDN here). So, for your OnFileOpen, you might do this:

AfxGetApp()->AddToRecentFileList(FilePathName);

As the remarks in MSDN say:

You should call the LoadStdProfileSettings member function to load the current MRU file list before you use this member function.

The framework calls this member function when it opens a file or executes the Save As command to save a file with a new name.

Upvotes: 1

Related Questions