Solved

Clearing Previous File History again ??

Posted on 1998-09-29
2
501 Views
Last Modified: 2009-07-29
    Most window apps have a option under their file menu, that lists the few most recently opened files (MRUs). Any body know how I can write an function so that my application can clear the invalid items whenever the file menu is pulled down.

     The application I am writing is 16 bit. That is VC ++ ver 1.52 using MFC ver 2.0. So there is no CRecentFileList class avaliable.

     I already can clear the invalid files at startup i.e check the m_strRecentFiles and clear away the no longer existing ones during the InitInstance. How do I do it when ever the user opens the file menu. The OnUpdateCommandUI should work, but how do I get it to display the rest of the valid files after. What does the windows frame work do to display the recent files list?

Thanks !!
0
Comment
Question by:manx
2 Comments
 
LVL 3

Accepted Solution

by:
plaroche earned 50 total points
ID: 1173982
I don't know VC 1.52 so i am not sure that he entire solution applies.  You are on the right track with OnUpdateCommandUI.

Under MFC it's the CWinApp that updates this list by simply calling the CRecentFileList::UpdateMenu(). This is done in:
      ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnUpdateRecentFileMenu)

This ID seen here (ID_FILE_MRU_FILE1) is the only one placed in the menu, when the update is done on this ID what is done is to add menu items, starting at the given ID.  Then, to trap the user's choice:
      ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)

Here is the UpdateMenu code, since you don't have a CRecentFileList in VC 1.52 you might be able to replicate this code yourself:

void CRecentFileList::UpdateMenu(CCmdUI* pCmdUI)
{
      ASSERT(m_arrNames != NULL);

      CMenu* pMenu = pCmdUI->m_pMenu;
      if (m_strOriginal.IsEmpty() && pMenu != NULL)
            pMenu->GetMenuString(pCmdUI->m_nID, m_strOriginal, MF_BYCOMMAND);

      if (m_arrNames[0].IsEmpty())
      {
            // no MRU files
            if (!m_strOriginal.IsEmpty())
                  pCmdUI->SetText(m_strOriginal);
            pCmdUI->Enable(FALSE);
            return;
      }

      if (pCmdUI->m_pMenu == NULL)
            return;

      for (int iMRU = 0; iMRU < m_nSize; iMRU++)
            pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID + iMRU, MF_BYCOMMAND);

#ifndef _MAC
      TCHAR szCurDir[_MAX_PATH];
      GetCurrentDirectory(_MAX_PATH, szCurDir);
      int nCurDir = lstrlen(szCurDir);
      ASSERT(nCurDir >= 0);
      szCurDir[nCurDir] = '\\';
      szCurDir[++nCurDir] = '\0';
#endif

      CString strName;
      CString strTemp;
      for (iMRU = 0; iMRU < m_nSize; iMRU++)
      {
#ifndef _MAC
            if (!GetDisplayName(strName, iMRU, szCurDir, nCurDir))
                  break;
#else
            if (!GetDisplayName(strName, iMRU, NULL, 0))
                  break;
#endif
            // double up any '&' characters so they are not underlined
            LPCTSTR lpszSrc = strName;
            LPTSTR lpszDest = strTemp.GetBuffer(strName.GetLength()*2);
            while (*lpszSrc != 0)
            {
                  if (*lpszSrc == '&')
                        *lpszDest++ = '&';
                  if (_istlead(*lpszSrc))
                        *lpszDest++ = *lpszSrc++;
                  *lpszDest++ = *lpszSrc++;
            }
            *lpszDest = 0;
            strTemp.ReleaseBuffer();

            // insert mnemonic + the file name
            TCHAR buf[10];
            wsprintf(buf, _T("&%d "), (iMRU+1+m_nStart) % 10);
            pCmdUI->m_pMenu->InsertMenu(pCmdUI->m_nIndex++,
                  MF_STRING | MF_BYPOSITION, pCmdUI->m_nID++,
                  CString(buf) + strTemp);
      }

      // update end menu count
      pCmdUI->m_nIndex--; // point to last menu added
      pCmdUI->m_nIndexMax = pCmdUI->m_pMenu->GetMenuItemCount();

      pCmdUI->m_bEnableChanged = TRUE;    // all the added items are enabled
}


I don't see why this shouldn't work, unless some functionality is used that doesn't exist in 1.52.
0
 

Author Comment

by:manx
ID: 1173983
Good Answer. Some of the functionality does not exist, but I managed to improvise my way through.

Thank You plaroche!!!!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now