Solved

Clearing Previous File History again ??

Posted on 1998-09-29
2
507 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

776 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