Share via


CContextMenuManager Class

The CContextMenuManager object manages shortcut menus, also known as context menus.

class CContextMenuManager : public CObject

Members

Public Constructors

Name

Description

CContextMenuManager::CContextMenuManager

Constructs a CContextMenuManager object.

CContextMenuManager::~CContextMenuManager

Destructor.

Public Methods

Name

Description

CContextMenuManager::AddMenu

Adds a new shortcut menu.

CContextMenuManager::GetMenuById

Returns a handle to the menu associated with the provided resource ID.

CContextMenuManager::GetMenuByName

Returns a handle to the menu that matches the provided menu name.

CContextMenuManager::GetMenuNames

Returns a list of menu names.

CContextMenuManager::LoadState

Loads shortcut menus stored in the Windows registry.

CContextMenuManager::ResetState

Clears the shortcut menus from the context menu manager.

CContextMenuManager::SaveState

Saves shortcut menus to the Windows registry.

CContextMenuManager::SetDontCloseActiveMenu

Controls whether the CContextMenuManager closes the active shortcut menu when it shows a new shortcut menu.

CContextMenuManager::ShowPopupMenu

Displays the specified shortcut menu.

CContextMenuManager::TrackPopupMenu

Displays the specified shortcut menu. Returns the index of the selected menu command.

Remarks

CContextMenuManager manages shortcut menus and makes sure that they have a consistent appearance.

You should not create a CContextMenuManager object manually. The framework of your application creates the CContextMenuManager object. However, you should call CWinAppEx::InitContextMenuManager when your application is initialized. After initializing the context manager, use the method CWinAppEx::GetContextMenuManager to obtain a pointer to the context manager for your application.

You can create shortcut menus at runtime by calling AddMenu. If you want to show the menu without first receiving user input, call ShowPopupMenu. TrackPopupMenu is used when you want to create a menu and wait for user input. TrackPopupMenu returns the index of the selected command or 0 if the user exited without selecting anything.

The CContextMenuManager can also save and load its state to the Windows registry.

Example

The following example demonstrates how to add a menu to a CContextMenuManager object, and how not to close the active pop-up menu when the CContextMenuManager object displays a new pop-up menu. This code snippet is part of the Custom Pages sample.

    // The GetContextMenuManager method is inherited from the CWinAppEx class.
    GetContextMenuManager()->AddMenu (_T("My menu"), IDR_CONTEXT_MENU);
    GetContextMenuManager()->SetDontCloseActiveMenu(true);

Inheritance Hierarchy

CObject

   CContextMenuManager

Requirements

Header: afxcontextmenumanager.h

See Also

Reference

Hierarchy Chart

CWinAppEx Class

CWinAppEx::InitContextMenuManager

Other Resources

MFC Classes