RecentFileList.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:2k
- #include "stdafx.h"
- #include "RecentFileList.h"
- void CRecentFileListEx::UpdateMenu(CCmdUI* pCmdUI)
- {
- int index = 0;
- ASSERT(m_arrNames != NULL);
- //注意不是pCmdUI->m_pMenu
- CMenu* pMenu = pCmdUI->m_pSubMenu;
- 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_pSubMenu == NULL)
- return;
- for (int iMRU = 0; iMRU < m_nSize; iMRU++)
- pCmdUI->m_pSubMenu->DeleteMenu(pCmdUI->m_nID + iMRU, MF_BYCOMMAND);
- TCHAR szCurDir[_MAX_PATH];
- GetCurrentDirectory(_MAX_PATH, szCurDir);
- int nCurDir = lstrlen(szCurDir);
- ASSERT(nCurDir >= 0);
- szCurDir[nCurDir] = '\';
- szCurDir[++nCurDir] = ' ';
- CString strName;
- CString strTemp;
- for (iMRU = 0; iMRU < m_nSize; iMRU++)
- {
- if (!GetDisplayName(strName, iMRU, szCurDir, nCurDir))
- break;
- // 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_pSubMenu->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_pSubMenu->GetMenuItemCount();
- pCmdUI->m_bEnableChanged = TRUE; // all the added items are enabled
- }