Share via


CMDIFrameWnd::MDISetMenu

Reemplaza el menú de una ventana de marco MDI, en el menú emergente de ventana, o ambos.

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

Parámetros

  • pFrameMenu
    Especifica el menú del menú nuevo de la cuadro- ventana.Si NULL, el menú no cambia.

  • pWindowMenu
    Especifica el menú del menú emergente de nueva ventana.Si NULL, el menú no cambia.

Valor devuelto

Un puntero al menú de la cuadro- ventana reemplazado por este mensaje.el puntero puede ser temporal y no se debe almacenar para su uso posterior.

Comentarios

Después de llamar a MDISetMenu, una aplicación debe llamar a la función miembro de DrawMenuBar de CWnd para actualizar la barra de menús.

Si esta llamada reemplaza el menú emergente de la ventana, los elementos de menú de la ventana MDI secundaria se quitan del menú Ventana anterior y se agregan al menú emergente de la nueva ventana.

Si se maximiza una ventana secundaria MDI y esta llamada reemplaza el menú de la cuadro- ventana MDI, los controles de menú de Control y restauración se quitan del menú anterior de la cuadro- ventana y se agregan al nuevo menú.

No llame a esta función miembro si utiliza el marco para administrar las ventanas MDI secundarias.

Ejemplo

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

Requisitos

encabezado: afxwin.h

Vea también

Referencia

Clase CMDIFrameWnd

Gráfico de jerarquía

CWnd::DrawMenuBar

WM_MDISETMENU