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

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

  • Instead of only managing projects organizations do need to manage value! "Doing the right things" and "doing things right" are the essential ingredients for successful software and systems delivery. Unfortunately, with distributed delivery spanning multiple disciplines, geographies and time zones, many organizations struggle with teams working in silos, broken lines of communication, lack of collaboration, inadequate traceability, and poor project visibility. This often results in organizations "doing the …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds