다음을 통해 공유


CMenu::CreateMenu

메뉴를 만들고이에 연결 된 CMenu 개체입니다.

BOOL CreateMenu( );

반환 값

0이 메뉴를 만들었습니다. 그렇지 않으면 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