CWnd::GetMenu
检索指向此窗口的菜单。
CMenu* GetMenu( ) const;
返回值
标识菜单。 如果 CWnd 没有菜单,该值为 NULL。 如果 CWnd 是子窗口,则返回值是未定义的。
返回的指针可能是瞬态的,不应存储以供将来使用。
备注
因为它们没有菜单,不应使用子窗口使用此功能。
示例
void CMainFrame::OnCwndDeletefilemenu()
{
// This example deletes the leftmost popup menu or leftmost
// popup menu item from the application's main window.
CWnd* pMain = AfxGetMainWnd();
// The main window _can_ be NULL, so this code
// doesn't ASSERT and actually tests.
if (pMain != NULL)
{
// Get the main window's menu
CMenu* pMenu = pMain->GetMenu();
// If there is a menu and it has items, we'll
// delete the first one.
if (pMenu != NULL && pMenu->GetMenuItemCount() > 0)
{
pMenu->DeleteMenu(0, MF_BYPOSITION);
// force a redraw of the menu bar
pMain->DrawMenuBar();
}
// No need to delete pMenu because it is an MFC
// temporary object.
}
}
要求
Header: afxwin.h