|
This approach is available only within a context of a VSIP package. It does provide you richer access to tool box functionality. So here what you can do:
· Query for SVsToolbox service from the global service provider
· Get the IVsToolbox2 interface
· Enumerate items under a specific Tool box tab
· Get the IDataObject for each item under it.
The drawback to using SVsToolbox service is that IVsToolbox2 interface does not provide a way to access the tool box item name just like what DTE provides. The VSIP team is working on getting this fixed for future releases of Visual Studio. The code snippets below just enumerate over the items existing under the “Windows Forms” tab of the Tool Box.
The code assumes that the Tool Box is open in the IDE.
C++ code:
HRESULT hr = _Module.QueryService(SID_SVsToolbox, IID_IVsToolbox, (void**) &srpIVsToolbox);
if(SUCCEEDED(hr))
{
hr = srpIVsToolbox->EnumItems(L"Windows Forms",&srpETI);
if(SUCCEEDED(hr))
{
CComPtr<IDataObject> pData;
int count = 0;
while(srpETI->Next(1, &pData, NULL)==S_OK)
{
//Do whatever with the data object
if(pData)
{
pData.Release();
pData = NULL;
count++;
}
}
}
srpETI.Release();
srpIVsToolbox.Release();
}
C# Code:
IVsToolbox2 ivToolBox =
(IVsToolbox2)(GetService(typeof(SVsToolbox)));
//Enumerate tabs
IEnumToolboxItems pEnumItems;
ivToolBox.EnumItems("Windows Forms", out pEnumItems);
Microsoft.VisualStudio.OLE.Interop.IDataObject [] pDo =
new Microsoft.VisualStudio.OLE.Interop.IDataObject[1];
uint fetched;
int count =0;
while(pEnumItems.Next(1, pDo, out fetched)==NativeMethods.S_OK)
{
if(pDo[0]!=null)
{
pDo[0] = null;
count++;
}
}
Thanks
Dr. eX
|