Udostępnij za pośrednictwem


How to: Provide Context for a Tool Window

To implement context-sensitive Help, you must create a context bag that stores metadata for a particular environment component, such as a tool window. The procedure below receives a pointer to the context bag already created on the IVsWindowFrame object. For more information, see How to: Create a Context Bag or Subcontext Bag. Follow the steps to manage context for a tool window.

To manage context for a tool window

  1. To get a pointer to the context bag, call the GetProperty method and pass in a value of VSFPROPID_UserContext for the propid parameter.

    This returns a variant.

  2. Cast the returned variant to a IVsUserContext interface.

    You can use the following sample code.

    VARIANT v;
    IVsWindowFrame::GetProperty(VSFPROPID_UserContext, &v);
    IUnknown* pUnk;
    IVsUserContext* pContext;
       pUnk = v.pUnkVal;
       pUnk -> QI(IID_IVsUserContext, &pContext); 
    
  3. Add and remove context from the context bag by using the AddAttribute and the RemoveAttribute methods, respectively.

    Note

    For tool windows, you should update the context bag as frequently as context changes in the window.

Robust Programming

Following is a recommended schema for attributes and keywords:

  • Supply one generic keyword topic for the tool window.

  • For this option, use an F1 keyword that is unique to the tool window.

  • Supply one topic for the tool window and one for a selection or command within the tool window.

  • This option is used for a tool window that includes a selection or command for which you want to supply F1 Help. An example of such a tool window is the Command window. In this instance, use a general keyword for the command window and specific keywords for the commands. The keyword for the command window is added to the tool window's context bag, while the keyword for the command is added to the tool window's subcontext bag.

    Note

    Attributes are generally not added for a tool window.

See Also

Reference

AddAttribute

RemoveAttribute

IVsWindowFrame