共用方式為


CWnd::GetMenu

擷取指標到這個視窗的功能表。

CMenu* GetMenu( ) const;

傳回值

識別功能表。 如果 CWnd 沒有功能表,這個值是 NULL 。 如果 CWnd 是子視窗,則傳回值為 undefined。

傳回的指標可能是暫時的,而且不應儲存供日後使用。

備註

因為它們沒有功能表,不應用於子視窗使用這個函式。

範例

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

請參閱

參考

CWnd 類別

階層架構圖

GetMenu