The simplest way to put the MRU list in a submenu

Environment: Tested on NT 4.0 SP3, VC6.0

Putting the MRU list in a submenu might appear just a matter to move the menu item ID_FILE_MRU_FILE1 from the 'File' menu to a submenu. Unfortunately a bug (of the CRecentFileList class I read but I believe that it's elsewhere in the framework) makes the things more complicated. As you can verify, even if it's unbelievable, the MRU list continues to appear in the main "File" menu! After some hours of deep desperation, I found a simple workaround. Once again, the solution came from an accurate analysis of the MFC code.

Using the ClassWizard, add the UPDATE_COMMAND_UI handler for the ID_FILE_MRU_FILE1 command to your application class and call it OnUpdateMruFile1. Then, just insert the following two lines of code:

void CMyApp::OnUpdateFileMruFile1(CCmdUI* pCmdUI) { 
	if (pCmdUI->m_nIndex == 0)
		OnUpdateRecentFileMenu(pCmdUI);
}

The OnUpdateRecentFileMenu() is the CWinApp own handler for ID_FILE_MRU_FILE1.

Note that the check:

	pCmdUI->m_nIndex == 0 

Relies on the fact that the ID_FILE_MRU_FILE1 item is the first item of its submenu. Therefore, the MRU list will never be updated if you insert some item before it.

I believe this be the simplest way to put the MRU list in a submenu.



Comments

  • Error with a handler function

    Posted by Legacy on 08/31/1999 12:00am

    Originally posted by: Shehzad Khan

    I've changed the "Recent Files" menu item to be a pop-up and added a handler:

    void CScoringModelDlg::OnUpdateFileMruFile1(CCmdUI* pCmdUI)
    {
    // TODO: Add your command update UI handler code here

    if (pCmdUI->m_nIndex == 0)
    OnUpdateRecentFileMenu(pCmdUI);
    }

    But I get this error:

    'OnUpdateRecentFileMenu' undeclared identifier.

    You've mentioned that this function is a CWinApp handler. I could not find it anywhere.

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

Top White Papers and Webcasts

  • Live Event Date: May 6, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT While you likely have very good reasons for remaining on WinXP after end of support -- an estimated 20-30% of worldwide devices still are -- the bottom line is your security risk is now significant. In the absence of security patches, attackers will certainly turn their attention to this new opportunity. Join Lumension Vice President Paul Zimski in this one-hour webcast to discuss risk and, more importantly, 5 pragmatic risk mitigation techniques …

  • You probably have several goals for your patient portal of choice. Is "community" one of them? With a bevy of vendors offering portal solutions, it can be challenging for a hospital to know where to start. Fortunately, YourCareCommunity helps ease the decision-making process. Read this white paper to learn more. "3 Ways Clinicians can Leverage a Patient Portal to Craft a Healthcare Community" is a published document owned by www.medhost.com

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds