Changing the Number of Files Displayed in the Most Recently Used (MRU) List

Environment: VC6

This article explains how to change the number of files that are displayed in the list of most recently used files that is displayed in the File menu.

How Is It Done?

In the class derived from CWinApp in a SDI or MDI application created by the Application Wizard there is a undocumented member m_pRecentFileList this is an object of the class CRecentFileList. This is the class that is used to display the MRU files in the menu. The class does not provide anyway to change the size without deleting the class and recreating it. Below is the method that is used to accomplish this:


#include <afxadv.h>        // This must be included for the
                           // CRecentFileList class

BOOL CMRUAppApp::ChangeMRUCount(UINT nCount)
{
  BOOL bReturn = FALSE;

  ASSERT(nCount <= 16);    // Make sure the value is not greater
                           // than 16

  // Make sure that the list is written to the Registry

  m_pRecentFileList->WriteList();

  // Get the place in the Registry and format from the original
  // CRecentFileList

  CString strSection     = m_pRecentFileList->m_strSectionName;
  CString strEntryFormat = m_pRecentFileList->m_strEntryFormat;

  // Delete current CRecentFileList

  delete m_pRecentFileList;

  // Create a new one

  m_pRecentFileList = new CRecentFileList(0, strSection,
                                             strEntryFormat,
                                             nCount);

  ASSERT(m_pRecentFileList);

  if(m_pRecentFileList)
  {
    bReturn = TRUE;

    // Reload list of MRU files from the Registry

    m_pRecentFileList->ReadList();
  }

  return bReturn;
}

To compile the code to use the m_pRecentFileList object, you must include the header afxadv.h.

The first thing the method does is to store the section in the Registry or application INI file where the MRU file list is stored and to get the string that is used to format the name of the entries stored in the Registry. The current object is then deleted and a new one created, using these stored values and the count of MRU files that was sent to the method. If this was created successfully, the list is read back from the Registry or INI file.

The Demo Project

The Demo project is a SDI application that has its view derived from CEditView to create a simple text editor. To test the example, open the text files and watch the MRU file list fill up. Initially, the number of files displayed is 4. To change the number, go to the Edit menu and click the Change MRU Count menu item. This displays a dialog where you then can change the number of files that will be displayed.

Downloads

Download demo project - 36 Kb


Comments

  • KZKLD ESE QDzM

    Posted by WefIyyIvLp on 04/14/2013 04:38pm

    tramadol online buy tramadol online no prescription next day delivery - buy tramadol online cheap no prescription

    Reply
  • When decrease the size of the recent file list, should update menu

    Posted by Legacy on 04/18/2003 12:00am

    Originally posted by: Jason Feng

    When decrease the size of the recent file list, should update menu

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • A majority of organizations are operating under the assumption that their network has already been compromised, or will be, according to a survey conducted by the SANS Institute. With many high profile breaches in 2013 occurring on endpoints, interest in improving endpoint security is top-of-mind for many information security professionals. The full results of the inaugural SANS Endpoint Security Survey are summarized in this white paper to help information security professionals track trends in endpoint …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds