This documentation is archived and is not being maintained.

How to: Create a Context Bag or Subcontext Bag

Context bags are used to store attribute and keyword context related to a particular environment component, such as an editor, hierarchy, or tool window. Subcontext bags are used to store attribute and keyword context for selections or commands within one of these components. For more information, see Context and Subcontext Bags.

Use the following procedure to create a context or subcontext bag.

To create a context or subcontext bag

  1. Call QueryService on your IServiceProvider interface for the SVsMonitorUserContext service.

    A pointer to the IVsMonitorUserContext interface is returned.

  2. Call the CreateEmptyContext method to create a new context or subcontext bag.

    A pointer to the IVsUserContext interface is returned.

  3. Call the AddAttribute method to add attributes, lookup keywords, or F1 keywords to the context or subcontext bag.

  4. If you are creating a subcontext bag, call the AddSubcontext method to link the subcontext bag to the parent context bag.

Show: