5,691,626 members and growing! (14,689 online)
Email Password   helpLost your password?
Desktop Development » Dialogs and Windows » General     Intermediate

Adding a Recent File List to an MFC dialog based application

By PPresedo

This article demonstrates how to add a recent file list to a dialog based application
VC6, C++Windows, NT4, Win2K, Visual Studio, MFC, Dev

Posted: 6 Jan 2001
Updated: 4 Sep 2001
Views: 63,966
Bookmarked: 23 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
25 votes for this Article.
Popularity: 6.29 Rating: 4.50 out of 5
2 votes, 16.7%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 8.3%
4
9 votes, 75.0%
5
  • Download demo project - 6 Kb
  • Download source - 18 Kb
  • Sample Image

    Introduction

    I am often writing simple utility applications for helping make life easier while programming. When I first started programming DOS applications I often wrote simple command line utilities to do some mundane tasks. When moving to the Windows world I continued to write the simple utilities as command line programs until I started using MFC. MFC dialog based applications gave me what I thought was the DOS command line utility of the Windows world.

    The one thing missing from MFC dialog based applications that I enjoyed using in many Windows applications was the use of the recent file list.

    It is actually not to difficult to add the recent file list capabilities to the MFC dialog based application. The first thing to do is add your menu to the dialog. Make sure you give it the IDR_MAINFRAME id. This is one of those special ids that MFC uses internally to do certain actions such as the recent file list. After you add your menu add an entry to that menu which contains the id ID_FILE_MRU_FILE1. After you have added the menu you will need to modify your applications CWinApp::InitInstance call. You will need to add two calls:

    SetRegistryKey(_T("CodeProject Recent File List Dialog Demo"));
    LoadStdProfileSettings(); // Load standard INI file options (including MRU)

    The SetRegistryKey will setup a location in the Windows registry database to store your applications recent file list entry. The LoadStdProfileSettings will load the standard INI file options which includes your applications most recent file list. You will also need to override the CWinApp::OpenDocumentFile function. This function is called when you select a file from your recent file list. You will notice in the sample application that the function returns 1 instead of a CDocument*. This can be done because the calling function CWinApp::OnOpenRecentFile does not use the return value. The last thing that needs to be done is to cause the menu to display your recent file list in the menu. This is done by overriding the WM_INITMENUPOPUP in your dialog box class. Inside the OnInitMenuPopup function you will force the calling of the OnUpdate handlers for the menus. In particular we need to call the OnUpdate handler CWinApp::OnUpdateRecentFileMenu for the recent file list menu item. When setting up the CCmdUI for calling the OnUpdateRecentFileMenu we need to be sure to set the m_nIndexMax value otherwise you will assert when there are no no recent files in the registry.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here

    About the Author

    PPresedo



    Occupation: Web Developer
    Location: United States United States

    Other popular Dialogs and Windows articles:

    Article Top
    Sign Up to vote for this article
    You must Sign In to use this message board.
    FAQ FAQ Noise ToleranceSearch Search Messages 
     Layout  Per page   
     Msgs 1 to 10 of 10 (Total in Forum: 10) (Refresh)FirstPrevNext
    GeneralThank you!memberChris Hills19:18 3 Dec '07  
    Generalhow to create menusmembery_naga_malleswararao3:36 14 Mar '06  
    Questionhaving a problem compiling your programmemberghulam-e-sirsabz8:09 1 Mar '06  
    AnswerRe: having a problem compiling your programmembershengcheng_jin16:42 7 Jun '07  
    GeneralProblem with dialog menumemberone_eddie3:55 27 Dec '04  
    GeneralHow do you "add a menu" to you Dialog based app?memberalbean12:10 9 Apr '02  
    GeneralRe: How do you "add a menu" to you Dialog based app?supporterChris Losinger12:16 9 Apr '02  
    GeneralRe: How do you "add a menu" to you Dialog based app?memberjefflewis11:05 24 Nov '05  
    GeneralRe: How do you "add a menu" to you Dialog based app?memberrems8119:36 14 Feb '06  
    GeneralhellomemberAnonymous11:14 7 Jan '01  

    General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

    PermaLink | Privacy | Terms of Use
    Last Updated: 4 Sep 2001
    Editor: Chris Maunder
    Copyright 2001 by PPresedo
    Everything else Copyright © CodeProject, 1999-2008
    Web10 | Advertise on the Code Project