CContextMenuManager Class
The CContextMenuManager object manages shortcut menus, also known as context menus.
class CContextMenuManager : public CObject
Members
Public Constructors
Name |
Description |
---|---|
Constructs a CContextMenuManager object. |
|
CContextMenuManager::~CContextMenuManager |
Destructor. |
Public Methods
Name |
Description |
---|---|
Adds a new shortcut menu. |
|
Returns a handle to the menu associated with the provided resource ID. |
|
Returns a handle to the menu that matches the provided menu name. |
|
Returns a list of menu names. |
|
Loads shortcut menus stored in the Windows registry. |
|
Clears the shortcut menus from the context menu manager. |
|
Saves shortcut menus to the Windows registry. |
|
Controls whether the CContextMenuManager closes the active shortcut menu when it shows a new shortcut menu. |
|
Displays the specified shortcut menu. |
|
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
Requirements
Header: afxcontextmenumanager.h
See Also
Reference
CWinAppEx::InitContextMenuManager