Click here to Skip to main content
Email Password   helpLost your password?
  • 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.

    You must Sign In to use this message board.
     
     
    Per page   
     FirstPrevNext
    GeneralThank you!
    Chris Hills
    19:18 3 Dec '07  
    Your explanation of OnInitMenuPopup was just what I needed to force the OnUpdate functions for my menu to be called. For some reason this usually happens only for menus in a normal window, but not in a dialog.
    Generalhow to create menus
    y_naga_malleswararao
    3:36 14 Mar '06  
    i want the code for creating menus in the dialog program and u had explained the recent files and did not explained the creation of menus so please tell me the creation of menus in this program it is so help ful for me.

    Thanks in advance


    Regards,
    Malli
    Questionhaving a problem compiling your program
    ghulam-e-sirsabz
    8:09 1 Mar '06  
    I always get an error when I try building the project both Debug and Relesae:

    Making help file...
    hlp\RecentFileListDlg.hpj(1) : error:
    The system cannot find the file specified.
    Error executing c:\windows\system32\cmd.exe.

    RecentFileListDlg.exe - 1 error(s), 0 warning(s)

    I wish I could just comment out the code which tries to make the help file but I can't find where this is being done in your code. I used your code succesfully in my own project to add files to the Recent File List, however when I call the UpdateMenu(CMenu *pMenu) in OnInitMenu(), my program crashes when I click on the menu in Release build. Debug build is OK.

    ghulam-e-sirsabz
    AnswerRe: having a problem compiling your program
    shengcheng_jin
    16:42 7 Jun '07  
    Hi,all you need is to delete this file.Then you can build your project success.

    www.codeproject.com is a good web for our programer.

    I like life and I think it is living.

    GeneralProblem with dialog menu
    one_eddie
    3:55 27 Dec '04  
    When i disable some items f.e in OnInitDialog, then when i enable them in f.e OnMenuMyCommand() (witch is called when i click on menu item)

    Those (enabled items) can be clicked but they are grayed until i "mouseover" on them.

    why?
    GeneralHow do you "add a menu" to you Dialog based app?
    albean
    12:10 9 Apr '02  
    In your article you state:
    "The first thing to do is add your menu to the dialog."

    Its probably a stupid question but how do you add a menu to the dailog based app. (I created an MFC App Wizard Dialog based app and included and about box but no menu appears.) I know you can right-click on the tile bar and have a pop up menu appear but your picture in the article shows a menu bar and I'm not sure how to build that.

    Thanks,
    Al


    GeneralRe: How do you "add a menu" to you Dialog based app?
    Chris Losinger
    12:16 9 Apr '02  
    double click on the dialog in the resource editor. on the first property page, you'll see a combo for "menu" - create a menu and select it there.

    -c


    A man usually falls in love with a woman who asks the kinds of questions he is able to answer.
       Ronald Colman
    Smaller Animals Software, Inc.

    GeneralRe: How do you "add a menu" to you Dialog based app?
    jefflewis
    11:05 24 Nov '05  
    wow - that's easy! thanks!

    GeneralRe: How do you "add a menu" to you Dialog based app?
    rems81
    19:36 14 Feb '06  
    But a menu on a dialog is not something which is common. Is there any disadvantage of using this? Normally a menu is loaded only on a resizable normal window. Any inputs??
    Generalhello
    Anonymous
    11:14 7 Jan '01  
    ??? Smile


    Last Updated 5 Sep 2001 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010