Getting rid of Window List from MDI applications

.

The MDI apps typically have a list of open windows. The list is
appended to a menu item which is 1 position to the left of the right
most menu item.

This is just ONE (simpler?) way of getting rid of it. There are other
methods which duplicate some MFC code in application and then suppress
WM_MDIREFRESHMENU message send.

I have not noticed any side effects of this. But use it at your own
risk.

1. Define a popup menu item under the menu item which is one position
left to the rightmost menu item. For example, given the following
layout, add an item under “Windows”.

File    Edit    View    Windows  Help

Dummy

2. Add a Menu Update Handler:

void MyApp::OnUpdateDummy(CCmdUI* pCmdUI)
{
	// TODO: Add your command update UI handler code here

	if (!m_pMainWnd)
	{
		return;
	}

	CMenu* pMenu = m_pMainWnd->GetMenu();

	ASSERT(pMenu);

//	CMenu* pWindowList = pMenu->GetSubMenu(4); //or 3? or 5?
	CMenu* pWindowList =
		((CMDIFrameWnd*)AfxGetMainWnd())->GetWindowMenuPopup(pMenu->m_hMenu);


	ASSERT (pWindowList);

	CCmdUI item;
	item.m_pMenu = pWindowList;

	item.m_nIndexMax = pWindowList->GetMenuItemCount();
	item.m_nIndex = 0;

	//loop thru all menu items
	for (;item.m_nIndex < item.m_nIndexMax; item.m_nIndex++)
	{
		item.m_nID = pWindowList->GetMenuItemID(item.m_nIndex);
		switch(item.m_nID)
		{
        case ID_DUMMY:
			//do whatever
			item.Enable(TRUE);
			break;
        default:
			pWindowList->DeleteMenu(item.m_nID, MF_BYCOMMAND);
			break;
		}
	}
}

More by Author

Must Read