Solved

Clearing Previous File History again ??

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

789 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