Re: How to delete the menu of "Recent Files"
solved
#include <afxadv.h>
ON_UPDATE_COMMAND_UI(ID_FILE_MRU_FILE1, OnMyMRU)
BOOL m_bMenusGone;
void CMdiApp::OnMyMRU(CCmdUI *pCmdUI)
{
// see if there are any MRU files
if (m_pRecentFileList == NULL || m_pRecentFileList->GetSize() == 0 ||
(*m_pRecentFileList)[0].IsEmpty())
{
// there are no files in the MRU. Did we already remove the stub menus?
if (!m_bMenusGone)
{
// no files at the moment. remove the menu item!
// pCmdUI->Enable(FALSE);
CMenu* pMenu = pCmdUI->m_pMenu;
if (pMenu != NULL)
{
// find the item equal to ID_APP_EXIT
UINT nExitID = 0;
int n;
for (n = pMenu->GetMenuItemCount()-1; n >= 0; n--)
{
UINT nTest = pMenu->GetMenuItemID(n);
if (ID_APP_EXIT == nTest)
{
nExitID = n;
break;
}
}
// if we didn't find it, or if there aren't at least
// two items above it, there's nothing we can do
if (nExitID >= 2)
{
pMenu->RemoveMenu(nExitID - 1, MF_BYPOSITION);
pMenu->RemoveMenu(nExitID - 2, MF_BYPOSITION);
}
}
m_bMenusGone = TRUE;
}
}
else
{
// there are files in the list! carry on with normal handling
m_pRecentFileList->UpdateMenu(pCmdUI);
}
}
void CMdiApp::HandleMRU(CMenu *pMenu)
{
// if we're about to display the menu, check to see if the separator and
// mru items are gone
ASSERT(pMenu != NULL);
if (m_bMenusGone)
{
// got menus? if we don't have any MRUs, then there is no reason to
// add anything back to the menu.
if (m_pRecentFileList != NULL && m_pRecentFileList->GetSize() != 0 &&
!(*m_pRecentFileList)[0].IsEmpty())
{
// got menus! This code assumes that the file menu is the
// first one.
CMenu* pFileMenu = pMenu->GetSubMenu(0);
ASSERT(pFileMenu != NULL);
if (pFileMenu != NULL)
{
int nCount = pFileMenu->GetMenuItemCount();
pFileMenu->InsertMenu(nCount - 2, MF_BYPOSITION | MF_STRING,
ID_FILE_MRU_FILE1, _T("x"));
pFileMenu->InsertMenu(nCount - 2, MF_BYPOSITION | MF_SEPARATOR);
m_bMenusGone = FALSE;
}
}
}
return;
}
void CMainFrame::OnInitMenu(CMenu* pMenu)
{
CMDIFrameWnd::OnInitMenu(pMenu);
CMRULessApp* pApp = (CMRULessApp*) AfxGetApp();
ASSERT(pApp != NULL);
pApp->HandleMRU(pMenu);
}
that's ok....