IVsUserContext.AddSubcontext Method

Links a subcontext bag to a parent context bag.

Namespace:  Microsoft.VisualStudio.Shell.Interop
Assembly:  Microsoft.VisualStudio.Shell.Interop (in Microsoft.VisualStudio.Shell.Interop.dll)

Syntax

'Declaration
Function AddSubcontext ( _
    pSubCtx As IVsUserContext, _
    lPriority As Integer, _
    <OutAttribute> ByRef pdwCookie As UInteger _
) As Integer
int AddSubcontext(
    IVsUserContext pSubCtx,
    int lPriority,
    out uint pdwCookie
)
int AddSubcontext(
    [InAttribute] IVsUserContext^ pSubCtx, 
    [InAttribute] int lPriority, 
    [OutAttribute] unsigned int% pdwCookie
)
abstract AddSubcontext : 
        pSubCtx:IVsUserContext * 
        lPriority:int * 
        pdwCookie:uint32 byref -> int
function AddSubcontext(
    pSubCtx : IVsUserContext, 
    lPriority : int, 
    pdwCookie : uint
) : int

Parameters

  • pdwCookie
    Type: System.UInt32%

    [out, retval] Pointer to a unique identifier for the subcontext.

Return Value

Type: System.Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

Remarks

COM Signature

From context.idl:

HRESULT IVsUserContext::AddSubcontext(
   [in] IVsUserContext * pSubCtx,
   [in] int lPriority,
   [out, retval] VSCOOKIE * pdwCookie
);

A context provider can contain an item for which a specific subcontext is required at run time. For example, command windows can require both context for the command window and subcontext for a selection within the command window. To add subcontext for a selection within a context provider, you need to first create a subcontext bag to hold the subcontext. For more information, see Creating a Context or Subcontext Bag. Once the subcontext bag is created, call AddAttribute to add attributes, lookup keywords, or F1 keywords to the subcontext bag. You can then call IVsUserContext.AddSubcontext to link the subcontext bag to the parent context bag.

For context bags, the priority of the context is automatically assigned by the environment based on what the context bag is hooked up to, such as the editor window, tool window, and so on. However, for subcontext, you need to set the priority yourself. In the case of a selection within a command window (tool window), the new subcontext is given an lPriority value of VSUC_Priority_ToolWndSel. When the commands change in the command window, the command name is then placed in the subcontext bag.

The IVsUserContext.AddSubcontext method returns a pointer to a unique identifier for the subcontext bag in terms of the context bag. Save this pointer and use it with the RemoveSubcontext method to delete the subcontext.

.NET Framework Security

See Also

Reference

IVsUserContext Interface

Microsoft.VisualStudio.Shell.Interop Namespace