Solved

Clearing Previous File History again ??

Posted on 1998-09-29
2
526 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

707 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