|
Principle of recently opened file list
In order to implement the recently opened file list function of the dialog box application, firstly, the implementation method of the recently opened file list of the MDI and SDI applications needs to be introduced. Because it is done automatically by the document / view framework, implementation details are implicit in MDI and SDI applications.
In MFC's MDI and SDI applications, there is a menu resource item ID_FILE_MRU_FILE1. When the application runs, MFC automatically converts this menu item into a list of files recently opened by the user. The menu update is triggered by the WM_INITMENU message. In the source code appui.cpp of the MFC, you can see the ID_FILE_MRU_FILE1 update processing function
ON_UPDATE_COMMAND_UI (ID_FILE_MRU_FILE1, OnUpdateRecentFileMenu)
ON_COMMAND_EX_RANGE (ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
When the user activates a menu item, Windows sends a WM_INITMENU message to the application, MFC sends an ON_UPDATE_COMMAND_UI message to all items in the menu, and the processing function of ID_FILE_MRU_FILE1 is OnUpdateRecentFileMenu, so it is called. Here is the implementation of the function:
void CWinApp :: OnUpdateRecentFileMenu (CCmdUI * pCmdUI)
{
ASSERT_VALID (this);
if (m_pRecentFileList == NULL) // no MRU files
pCmdUI-> Enable (FALSE);
else
m_pRecentFileList-> UpdateMenu (pCmdUI);
} |
|