CMDIFrameWnd::MDISetMenu

Sostituisce il menu di una finestra cornice MDI, il menu di scelta rapida della finestra, o di entrambi.

CMenu* MDISetMenu(
   CMenu* pFrameMenu,
   CMenu* pWindowMenu 
);

Parametri

  • pFrameMenu
    Specifica il menu della finestra.Se NULL, menu non viene modificato.

  • pWindowMenu
    Specifica il menu del menu di scelta rapida della nuova finestra.Se NULL, menu non viene modificato.

Valore restituito

Un puntatore alla finestra sostituita da questo messaggio.Il puntatore può essere temporanei e non deve essere archiviata per un utilizzo successivo.

Note

Dopo aver chiamato MDISetMenu, un'applicazione deve chiamare la funzione membro DrawMenuBarCWnd per aggiornare la barra dei menu.

Se questa chiamata sostituisce il menu di scelta rapida della finestra, le voci del menu finestra figlio MDI vengono rimosse dalla finestra precedente e aggiunto al menu di scelta rapida della nuova finestra.

Se una finestra figlio MDI viene ingrandita e questa chiamata sostituisce la finestra MDI, i comandi dei menu del controllo e di ripristino vengono rimossi dalla finestra precedente e aggiunti al nuovo menu.

Non chiamare la funzione membro se si utilizza il framework per gestire le finestre figlio MDI.

Esempio

// CMdiView::OnReplaceMenu() is a menu command handler for CMdiView
// class, which in turn is a CView-derived class. It loads a new
// menu resource and replaces the main application window's menu
// bar with this new menu.
void CMdiView::OnReplaceMenu() 
{
   // Load a new menu resource named IDR_SHORT_MENU. m_hDefaultMenu is 
   // a member variable of CMdiDoc class (a CDocument-derived class). 
   // Its type is HMENU.
   CMdiDoc* pdoc = (CMdiDoc*)GetDocument();
   pdoc->m_hDefaultMenu = 
      ::LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_SHORT_MENU));
   if (pdoc->m_hDefaultMenu == NULL)
      return;

   // Get the parent window of this view window. The parent window is
   // a CMDIChildWnd-derived class. We can then obtain the MDI parent 
   // frame window using the CMDIChildWnd*. Then, replace the current 
   // menu bar with the new loaded menu resource.
   CMDIFrameWnd* frame = ((CMDIChildWnd*)GetParent())->GetMDIFrame();
   frame->MDISetMenu(CMenu::FromHandle(pdoc->m_hDefaultMenu), NULL);
   frame->DrawMenuBar();
}
// GetDefaultMenu() is an undocumented virtual function for 
// CDocument class. It allows the document to determine which 
// menu to display. m_hDefaultMenu is of type HMENU. Its value
// is initialized to NULL either in the constructor or 
// CDocument::OnNewDocument(). And the menu resource is destroyed
// in the destructor to avoid having too many menus loaded at once.
HMENU CMdiDoc::GetDefaultMenu()
{
   if (m_hDefaultMenu)
      return m_hDefaultMenu;

   return COleServerDoc::GetDefaultMenu();
}

// Initialize member variable(s) in the constructor. CMdiDoc is
// a CDocument-derived class.
CMdiDoc::CMdiDoc()
{
   // Use OLE compound files
   EnableCompoundFile();

   m_hDefaultMenu = NULL; // initialize to NULL
}

// Destroy menu resource in CMdiDoc's destructor. CMdiDoc is
// a CDocument-derived class.
CMdiDoc::~CMdiDoc()
{
   if (m_hDefaultMenu)
      ::DestroyMenu(m_hDefaultMenu);
}

Requisiti

Header: afxwin.h

Vedere anche

Riferimenti

Classe di CMDIFrameWnd

Grafico della gerarchia

CWnd::DrawMenuBar

WM_MDISETMENU