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.
   }
}

必要条件

**ヘッダー:**afxwin.h

参照

参照

CWnd クラス

階層図

GetMenu

概念

CWnd のメンバー