How to add command handlers for MRU menu items in MFC applications (243751)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
- Microsoft Visual C++ .NET (2002)
- Microsoft Visual C++ .NET (2003)
- Microsoft Visual C++ 2005 Express Edition
This article was previously published under Q243751 Note Microsoft Visual C++ .NET 2002 and Microsoft Visual C++ .NET 2003 support both the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. The information in this article applies only to unmanaged Visual C++ code. Microsoft Visual C++ 2005 supports the managed code model that is provided by the Microsoft .NET Framework and the unmanaged native Microsoft Windows code model. SUMMARY AppWizard generated Microsoft Foundation Class (MFC)
SDI/MDI applications (with doc/view architecture support) have a Recent File menu item under the File menu with ID_FILE_MRU_FILE1 as control ID. MFC framework replaces
this menu item with the names of the files the you most recently opened. It
replaces the single menu item ID_FILE_MRU_FILE1 with a sequence of menu items
ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE2 and so on for as many file names there are
in the list. MRU support is enabled for an application automatically by calling
LoadStdProfileSettings in InitInstance method of application class and passing
the number of recent files you want to support as a parameter.
CWinApp has a command handler, OnOpenRecentFile, for IDs ID_FILE_MRU_FILE1 to
ID_FILE_MRU_FILE16. When you select one of the MRU menu items, control passes
to CWinApp::OnOpenRecentFile, which tries to open the file by calling
OpenDocumentFile with the name of the document.
You might want to
override this behavior in order to have your own processing for these menu
items or to support more than 16 menu items. You can do this by adding command
handlers for ID_FILE_MRU_FILE1 to ID_FILE_MRU_FILEn in your application class.
ClassWizard lets you add handler for the first MRU menu item only. You would
have to add handlers for the remaining MRU menu items manually or have the same
command handler for all MRU menu items by using ON_COMMAND_RANGE macro. REFERENCES For more information look up the following in the Microsoft
Developer's Network (MSDN):
- ON_COMMAND macros
- ON_COMMAND_RANGE macros
- AppCore.cpp files in MFC source directory
- AppUI.cpp files in MFC source directory
Modification Type: | Major | Last Reviewed: | 1/7/2006 |
---|
Keywords: | kbhowto kbMenu KbUIDesign KB243751 kbAudDeveloper kbAudITPRO |
---|
|