Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

CWnd::GetMenu

Retrieves a pointer to the menu for this window.

CMenu* GetMenu( ) const;

Identifies the menu. The value is NULL if CWnd has no menu. The return value is undefined if CWnd is a child window.

The returned pointer may be temporary and should not be stored for later use.

This function should not be used for child windows because they do not have a menu.

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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.