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: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • Relying on outside companies to manage your network and server environments for your business and applications to meet the needs and demands of your users can be stressful. This is especially true as many Managed Hosting organizations fail to meet their service level agreements. Read this Forrester total economic impact report and learn what makes INetU different and how they exceed their customers' managed hosting expectations.

Most Popular Programming Stories

More for Developers

RSS Feeds