CMenu::CreateMenu

メニューを作成し、CMenu のオブジェクトにアタッチします。

BOOL CreateMenu( );

戻り値

メニューが正常に作成された場合は、; それ以外の場合は 0。

解説

メニューは最初は空です。メニュー項目は AppendMenu または InsertMenu のメンバー関数を使用して追加できます。

メニューがウィンドウに割り当てられている場合、ウィンドウが破棄されるときに自動的に破棄されます。

終了する前に、アプリケーションはメニューがウィンドウに割り当てるメニューに関連付けられているシステム リソースを解放する必要があります。アプリケーションは DestroyMenu のメンバー関数を呼び出して、メニューを解放します。

使用例

// The code fragment below shows how to create a new menu for the
// application window using CreateMenu() and CreatePopupMenu().
// Then, the created menu will replace the current menu of the
// application. The old menu will be destroyed with DestroyMenu().
// NOTE: The code fragment below is done in a CFrameWnd-derived class.

// Create a new menu for the application window.
VERIFY(m_NewMenu.CreateMenu());

// Create a "File" popup menu and insert this popup menu to the
// new menu of the application window. The "File" menu has only
// one menu item, i.e. "Exit".
VERIFY(m_FileMenu.CreatePopupMenu());
m_FileMenu.AppendMenu(MF_STRING, ID_APP_EXIT, _T("E&xit"));
m_NewMenu.AppendMenu(MF_POPUP, (UINT_PTR)m_FileMenu.m_hMenu, _T("&File"));

// Remove and destroy old menu
SetMenu(NULL);
CMenu* old_menu = CMenu::FromHandle(m_hMenuDefault);
old_menu->DestroyMenu();

// Add new menu.
SetMenu(&m_NewMenu);

// Assign default menu
m_hMenuDefault = m_NewMenu.m_hMenu;

必要条件

ヘッダー: afxwin.h

参照

関連項目

CMenu クラス

階層図

CMenu::CMenu

CMenu::DestroyMenu

CMenu::InsertMenu

CWnd::SetMenu

CreateMenu

CMenu::AppendMenu