Adding Most Recently Used(MRU)FilestoanSDI/MDI Application

Adding MRU to MFC SDI or MDI is actually not very difficult. I just add ?AddToRecentFileList(LPCTSTR lpszPathName) to ?CDocument derived class which calls the add the path name to ?CWinApp’s ?CRecentFileList (m_pRecentFileList). I use SDI for this demo.


1. Iinclude afxadv.h to stdafx.h. This contains the class ?CRecentFileList.
#include <afxadv.h>


2. Add ?AddToRecentFileList to ?CDocument derived class and use this function during opening and saving the document.

void CCMRUTestDoc::AddToRecentFileList(LPCTSTR lpszPathName)
BOOL CCMRUTestDoc::OnOpenDocument(LPCTSTR lpszPathName) 
    if (!CDocument::OnOpenDocument(lpszPathName))
        return FALSE;
    /* Add to MRU file list */ 
    return TRUE;