VC Multiple MRU Menu issues

Source: Internet
Author: User

Q: I imagine DevStudio97 to separate the MRU submenus for different document types, such as breaking into the most recent workspace and the most recently opened file. I looked for it on the CodeGuru, but I didn't get anything.

A: This can be solved. I've kept the CRecentFileList object, let the MFC framework manage the default document type, and then added a handle to the second document type, and I'm going to go step-by-step through the problem:

Using custom menu IDs, such as Id_file_mru_myfile1, you should also add Id_file_mru_myfile2, Id_file_mru_myfile3, ... in the string table. id_file_mru_myfile##

  1. To add a new member to the Application class: Crecentfilelist* m_precentlistmyfiles;
  2. In the initialization InitInstance () Add the following code:

    M_precentlistmyfiles =new crecentfilelist (5, "My recent File List", "myfile%d", 5);

    M_precentlistmyfiles->readlist ();

  3. In ExitInstance () add m_precentlistmyfiles->writelist ();
  4. Add the UI processing Update_command_ui:m_precentlistmyfiles->updatemenu (pCmdUI) to the Id_file_mru_myfile1;
  5. Add the following code to the application message map: On_command_ex_range (Id_file_mru_myfile1, Id_file_mru_myfile##,onopenrecentmyfile)
  6. The following is the handler function for the above message: BOOL cmyapp::onopenrecentmyfile (UINT NID)
    {
    int nindex = nid-id_file_mru_myfile1;
      if (OpenDocumentFile (*m_precentlistmyfiles) [nindex]) = = NULL)
    M_precentlistmyfiles->remove (nindex);
    return TRUE;
    }
  7. Overloaded cwinapp::addtorecentfilelist () void Ck2App::AddToRecentFileList(LPCTSTR lpszPathName)
      {
      // Somehow determine doc type, I used file extension
      CString strExt;
      CString strPathName = lpszPathName;
      int nPos = strPathName.ReverseFind( '.' );
      if ( nPos != -1 )
          strExt = strPathName.Mid( nPos + 1 );
      if ( strExt.CompareNoCase( "XXX" ) == 0 )
        {
        if (m_pRecentListMyFiles!= NULL)
          {
            // fully qualify the path name
            TCHAR szTemp[_MAX_PATH];
            AfxFullPath(szTemp, lpszPathName);
            // then add to recent file list
            m_pRecentListMyFiles->Add(szTemp);
          }
        }
        else  // Otherwise, let base class put it on default MRU
          CWinApp::AddToRecentFileList(lpszPathName);
      }
  8. And, of course, don't forget to delete M_precentlistmyfiles in the application's destructor.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.