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;
		}
	}
}



Comments

  • Getting rid of Window List from MDI applications

    Posted by Legacy on 03/04/1999 12:00am

    Originally posted by: Serguei Batchila

    "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." That's not true. List is appended to submenu which has at least one item with ID between AFX_IDM_WINDOW_FIRST and AFX_IDM_WINDOW_LAST. See the source code of function CMDIFrameWnd::GetWindowMenuPopup(HMENU hMenuBar), file "WINMDI.CPP" from MFC sources. AFX_IDM_WINDOW_### constants are defined in "AFXRES.H". By the way, all standard commands from "Window" submenu (ID_WINDOW_CASCADE, ID_WINDOW_TILE_HORZ and so on) are between AFX_IDM_WINDOW_FIRST and AFX_IDM_WINDOW_LAST. That's why you have window list in "Window" submenu.

    The easiest way to get rid of Window List is
    1. to override virtual function CMDIFrameWnd::GetWindowMenuPopup(HMENU hMenuBar):
    CMyMDIFrameWnd::GetWindowMenuPopup(HMENU hMenuBar)
    {
    return NULL;
    }

    2. or remove these commands from "Window" menu:
    ID_WINDOW_NEW
    ID_WINDOW_ARRANGE
    ID_WINDOW_CASCADE
    ID_WINDOW_TILE_HORZ
    ID_WINDOW_TILE_VERT
    ID_WINDOW_SPLIT
    and make sure you do not have commands in "Window" menu with IDs between 0xE130(AFX_IDM_WINDOW_FIRST) and 0xE13F(AFX_IDM_WINDOW_LAST)

    I think the first way is better

    Reply
  • Getting rid of Window List from MDI applications, part II

    Posted by Legacy on 01/22/1999 12:00am

    Originally posted by: M. van Leeuwen

    Although nearly the same, another solution. Call this method from any update command for an entry in the
    before last menu, like:
    
    DeleteWindowList(pCmdUI->m_pMenu);
    Benefits are that only the mdichildwindow menu-entries are deleted and the separator above it (presuming your IDs don't exceed 65280).

    void AClass::DeleteWindowList(CMenu *pMenu)
    {
    // Get rid of the list of open windows.
    if ( pMenu == NULL)
    return;

    int i, count, current, previous = -1;

    // Cycle through all the items in the list. If
    // it comes across MDI Child windows, remove
    // them from the list.
    count = pMenu->GetMenuItemCount();

    if ( count == -1 )
    return;

    for ( i=0; i < count; ++i )
    {
    current = pMenu->GetMenuItemID(i);

    if ( current >= AFX_IDM_FIRST_MDICHILD )
    {
    pMenu->DeleteMenu(i, MF_BYPOSITION);

    // If the previous item is a separator,
    // remove it also from the menu.
    if ( previous == 0 )
    pMenu->DeleteMenu(i-1, MF_BYPOSITION);
    }
    previous = current;
    }
    }


    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • What does it take to win? According to Jack Welch, winning in business is great because when companies win, people thrive and grow. However, it goes without saying that you have to win the right way -- cleanly and by the rules. Even the most talented businessperson with the best intentions will get nowhere unless he or she knows how to win in today's complex business world. Read this book summary to learn not only the strategies of winning, but also the value that those strategies bring to your professional …

  • Cloud computing isn't new, but it's still a hot topic in technology circles. Moving to the cloud has done great things for many businesses. When it comes to handling a basic business necessity, cloud computing has brought many improvements to overall business continuity. Using the cloud for DR makes a lot of sense for many, but it's not exactly the most simple concept. Read this eBook to find answers to all the key questions IT professionals have about cloud-based disaster recovery, and helpful info around the …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date