views:

129

answers:

1

I'd like the user to be able to edit the number of recent files shown in the File menu of my MFC application. I've used two very good references:

It involves deleting and recreating the CRecentFileList object stored in CWinApp::m_pRecentFileList. Unfortunately, I find that the menu is not updated properly after replacing the CRecentFileList. See code snippet below:

void CMyWinApp::SetMRUListSize( int size )
{
   // size guaranteed to be between 1 and 16
   delete m_pRecentFileList ;
   LoadStdProfileSettings( size ) ;
}

What can I do to ensure that what is drawn into the File menu is synchronized with m_pRecentFileList after I recreate the object?

A: 

Some of Microsoft's documentation suggest you should call CWinApp::LoadStdProfileSettings from within InitInstance. This suggests to me that it's something done once during initialisation rather than at run time.

Have you tried fully implementing the second of the two links you provided? My guess is you need to add the second part instead of the call to CWinApp::LoadStdProfileSettings:

m_pRecentFileList = new CRecentFileList(0, strSection, strEntryFormat, nCount);
if(m_pRecentFileList)
{
    bReturn = TRUE;

    // Reload list of MRU files from registry
    m_pRecentFileList->ReadList();
}

[Edit] Apparently m_pRecentFileList points to an CRecentFileList Class . Have you tried calling CRecentFileList::UpdateMenu?

There's another CodeProject example which might help too.

Jon Cage
You might be right - I have changed the code accordingly, but the menu is still not updating correctly after programatically changing the number of recent files. Specifically, reducing the number of recent files displayed does not reduce the total number of recent files shown.
swongu