| |

VerySource

 Forgot password?
 Register
Search
View: 633|Reply: 3

Questions about "Recently Opened Documents"

[Copy link]

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-5 18:20:01
| Show all posts |Read mode
I now want to change the "Recent File" menu item in the "File" submenu of a single-document program into a pop-up menu. The most recent menu is then displayed. I read a reference book, but I didn't understand it, and troublesome masters explained it to me. The book reads:

1) Edit the menu resource, change the attribute of the "Recent File" menu item in the "File" submenu to popup, and remove the grayed attribute. Then add a menu item with the ID ID_FILE_MRU_FILE1 below it.
   (I understand the above steps)
2) Add the response function of the UPDAATE_COMMAND_UI message of the command ID_FILE_MRU_FILE1 in the application class, the code is as follows:
void CTestApp :: OnUpdateFileMruFile1 (CCmdUI * pCmdUI)
{
if (pCmdUI-> m_pSubMenu! = NULL) // What does this sentence mean?
{
return;
}
CWinApp :: OnUpdateRecentFileMenu (pCmdUI);
          // CWinApp class does not have the OnUpdateRecentFileMenu () member function, then this

         // What is the function?
}

I really can't understand this code, I just started, please masters don't laugh at me, and please be patient to explain it to me. What does the judgment of the if statement mean? What to judge?
Reply

Use magic Report

0

Threads

12

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-1-6 00:36:01
| Show all posts
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);

}
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-6 03:06:01
| Show all posts
I can't understand upstairs. The level is too bad. How to do
Reply

Use magic Report

1

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-1-6 08:24:01
| Show all posts
Upstairs, OnUpdateRecentFileMenu () is not a member function of the CWinApp class. What function is it
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list