Partager via


IVsUserContext.AddSubcontext(IVsUserContext, Int32, UInt32) Method

Definition

Links a subcontext bag to a parent context bag.

public:
 int AddSubcontext(Microsoft::VisualStudio::Shell::Interop::IVsUserContext ^ pSubCtx, int lPriority, [Runtime::InteropServices::Out] System::UInt32 % pdwCookie);
int AddSubcontext(Microsoft::VisualStudio::Shell::Interop::IVsUserContext const & pSubCtx, int lPriority, [Runtime::InteropServices::Out] unsigned int & pdwCookie);
public int AddSubcontext (Microsoft.VisualStudio.Shell.Interop.IVsUserContext pSubCtx, int lPriority, out uint pdwCookie);
abstract member AddSubcontext : Microsoft.VisualStudio.Shell.Interop.IVsUserContext * int * uint32 -> int
Public Function AddSubcontext (pSubCtx As IVsUserContext, lPriority As Integer, ByRef pdwCookie As UInteger) As Integer

Parameters

pSubCtx
IVsUserContext

[in] Pointer to the IVsUserContext interface (the subcontext bag).

lPriority
Int32

[in] Priority of the subcontext. For a list of lPriority values, see VSUSERCONTEXTPRIORITY.

pdwCookie
UInt32

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

Returns

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.

Applies to