Adding a Customozied 'More Windows...' Dialog to an MDI Application

To add a customized windows dialog to the windows menu, you just have to take only two following steps in the mainframe class...

  • Override InitPopupMenu and replace it with the following code :
  • #define DEFAULT_NUMBER_OF_MDIS 9
    
    void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, 
                                     UINT nIndex, 
                                     BOOL bSysMenu )
    {
     CMDIFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
    
     // If the number of active windows is zero, the window submenu 
     // probably does'nt esists. If you have the window submenu present
     // even in zero child windows, remove this code.
    
     int nCount = 0;
     CWnd * pWnd = GetWindow (GW_CHILD);
     ASSERT (pWnd);
     pWnd = pWnd->GetWindow (GW_CHILD);
     while (pWnd)
     {
      nCount++;
      pWnd = pWnd->GetWindow (GW_HWNDNEXT);
     }
    
     // The count is zero. exit.
     if ( nCount == 0 )
      return;
    
     // If it's a system menu, we don't need to handle that...
     if ( !bSysMenu )
     {
      // The default handler places the "more windows" command in the 
      // submenu which contains IDs between AFX_IDM_FIRST_MDICHILD and 
      // AFX_IDM_LAST_MDICHILD, so check the popup for occurence of
      // AFX_IDM_FIRST_MDICHILD.
    
      int nLength = pPopupMenu->GetMenuItemCount();
      for ( int i = 0; i < nLength; i++ ) 
      { 
       if ( pPopupMenu->GetMenuItemID( i ) == AFX_IDM_FIRST_MDICHILD )
       {
        // Found. If the last item is already the "more windows"
        // command than remove it.
        if ( pPopupMenu->GetMenuItemID( nLength - 1 ) == 
        AFX_IDM_FIRST_MDICHILD + DEFAULT_NUMBER_OF_MDIS ) 
        {
         pPopupMenu->DeleteMenu( nLength - 1, MF_BYPOSITION );
        }
    
        // Add our own window command.
        // Note : The ID must be - ( AFX_IDM_FIRST_MDICHILD +  
        // ( total number of entries in window list supported ) ). 
        // This saves us to make any default handler for the  
        // command, as the default procedure itself 
        // handles the command and sends it to the mainframe class.
        pPopupMenu->AppendMenu(MF_ENABLED|MF_STRING, 
                               AFX_IDM_FIRST_MDICHILD + DEFAULT_NUMBER_OF_MDIS,
                               "&Windows..." );
    
        // Done the processing.
        return;
       }
      }
     }
    }
    
  • Override OnCommand and replace it with the following code:
  • BOOL CMainFrame::OnCommand(WPARAM wParam, LPARAM lParam) 
    {
     // If the command is "more windows" command call our 
     // own customized dialog
     if ( wParam == AFX_IDM_FIRST_MDICHILD + 9 )
     {
      // Replace CWindowDlg with your own class
      CWindowDlg dlgWindowDlg;
      dlgWindowDlg.DoModal();
    
      // OK. We handled the command so return true, 
      // as we don't want the default handler to 
      // handle this command too.
      return TRUE;
     }
    
     return CMDIFrameWnd::OnCommand(wParam, lParam);
    }
    

Downloads

Download demo project - 22 Kb


Comments

  • There are no comments yet. Be the first to comment!

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

Top White Papers and Webcasts

  • Live Event Date: September 17, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Another day, another end-of-support deadline. You've heard enough about the hazards of not migrating to Windows Server 2008 or 2012. What you may not know is that there's plenty in it for you and your business, like increased automation and performance, time-saving technical features, and a lower total cost of ownership. Check out this upcoming eSeminar and join Rich Holmes, Pomeroy's practice director of virtualization, as he discusses the …

  • Live Event Date: September 16, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you starting an on-premise-to-cloud data migration project? Have you thought about how much space you might need for your online platform or how to handle data that might be related to users who no longer exist? If these questions or any other concerns have been plaguing you about your migration project, check out this eSeminar. Join our speakers Betsy Bilhorn, VP, Product Management at Scribe, Mike Virnig, PowerSucess Manager and Michele …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds