[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Clearing Previous File History again ??

Posted on 1998-09-29
2
Medium Priority
?
537 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 150 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

649 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