Step1:在VSpakage中实现IVsSelectionEvents接口;
Step2:在Initiliaze初始话函数中注册之:
IVsMonitorSelection ms = Package.GetGlobalService(typeof(IVsMonitorSelection)) as IVsMonitorSelection
if(ms != null)
{
ms.AdviseSelectionEvents(this, out cookie);
}
Step3:重点实现OnElementValueChanged方法;
1、elementid = Microsoft.VisualStudio.Shell.Interop.Constants.SEID_WindowFrame;
2、if(varNewValue is IVsWindowFrame) actvieWindowFrame = varNewValue as IVsWindowFrame;
Step4:通过FindToolWindow,查找当前的ToolWindow,比对其Frame字段是否与activeWindowFrame相等,若相当,则为当前选中的ToolWindow