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: 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 …

  • Businesses are moving more and more of their customer transactions to the web. Security is understandably a top concern as online transactions increase, so it is important to make sure your electronic signature provider meets the highest security standards. That means more than simply passing a security audit or obtaining a certification. This white paper provides recommendations for taking a broader view of e-signature security, and answers key questions that help identify the security requirements against …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds