更改最近使用列表(MRU)中显示的项数






4.67/5 (3投票s)
2003 年 4 月 10 日
1分钟阅读

59639
如何更改最近使用列表(MRU)
引言
本文档解释了如何更改在“文件”菜单中显示的最近使用文件列表中显示的文件数量。
它是如何实现的?
在由应用程序向导创建的 SDI 或 MDI 应用程序中,从 CWinApp
类派生的类中,有一个未公开的成员 m_pRecentFileList
。这是一个 CRecentFileList
类的对象。该类用于在菜单中显示 MRU 文件。该类不提供任何更改大小的方法,除非删除该类并重新创建它。以下是用于实现此目的的方法:
#include <afxadv.h> // This must be included for the CRecentFileList class
BOOL CMRUAppApp::ChangeMRUCount(UINT nCount)
{
BOOL bReturn = FALSE;
ASSERT(nCount <= 16); // Make sure value is not greater than 16
// Make sure that the list is written to registry
m_pRecentFileList->WriteList();
// Get place in registry and format from 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 registry
m_pRecentFileList->ReadList();
}
return bReturn;
关注点
为了能够编译使用 m_pRecentFileList
对象的代码,您必须包含头文件 afxadv.h。
该方法首先将 MRU 文件列表存储在注册表或应用程序 INI 文件中的部分存储起来,并获取用于格式化注册表中存储条目名称的 string
。然后删除当前对象,并使用这些存储的值以及发送到该方法的 MRU 文件计数创建新的对象。如果创建成功,则从注册表或 INI 文件中重新读取列表。
列表中最多只能有 16 个项目。
许可证
本文未附加明确的许可证,但可能在文章文本或下载文件本身中包含使用条款。如有疑问,请通过下面的讨论区联系作者。
作者可能使用的许可证列表可以在此处找到。