CMDIFrameWnd::MDISetMenu
替换MDI框架窗口中的菜单上,窗口弹出菜单或两个。
CMenu* MDISetMenu(
CMenu* pFrameMenu,
CMenu* pWindowMenu
);
参数
pFrameMenu
指定新框架窗口"菜单"中。 如果,菜单未更改 NULL。pWindowMenu
指定新窗口弹出菜单的菜单。 如果,菜单未更改 NULL。
返回值
此消息交换的框架窗口菜单的指针。 指针可能是瞬态的,不应存储以供将来使用。
备注
在调用 MDISetMenu后,应用程序必须调用 CWnd 的 DrawMenuBar 成员函数更新菜单栏。
如果此调用替换"窗口弹出菜单,MDI子窗口菜单项从上一个窗口菜单中移除并添加到新窗口弹出菜单。
如果MDI子窗口最大化,则调用替换MDI框架窗口菜单,控制菜单和还原控件以前框架窗口菜单中移除并将其添加到新菜单。
如果使用框架管理您的MDI子窗口,则不要调用该成员函数。
示例
// 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);
}
要求
Header: afxwin.h