仍然是在OnConnection中添加创建右键菜单的代码:
![](/Images/OutliningIndicators/None.gif)
string addinName = "垃圾清除";
![](/Images/OutliningIndicators/None.gif)
_addInInstance = (AddIn)addInInst;
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
menuItemHandler = (CommandBarEvents)_applicationObject.DTE.Events.get_CommandBarEvents(menuItem);
![](/Images/OutliningIndicators/None.gif)
上面一段代码,作用是在项目的右键菜单上增加一个名称为垃圾清除的菜单,CommandBars和CommandBar是用于管理命令栏的接口,通过
menuItemHandler = (CommandBarEvents)_applicationObject.DTE.Events.get_CommandBarEvents(menuItem);
menuItemHandler.Click += new _dispCommandBarControlEvents_ClickEventHandler(MenuItem_Click);
来添加子菜单的点击事件。
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
Click事件中是完成了对项目垃圾文件的清除和清除结果的输出,要想在输出窗口中输出自定义的内容,可以使用下面的方法
![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/InBlock.gif)
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
这篇文章参考了dudu老大的 VS 2005 Add-in开发随笔 ,非常老大为我指明了方向。
vs2005是一个扩展性比较强大的平台,虽然没有eclipse支持插件那样猛,可通过我们的挖掘,还是能在vs2005上安装不少装饰的,我这篇主要写了如何添加右键菜单和输出自定义内容,这个菜单主要完成的工作是清除项目文件夹中没有被项目引用的垃圾数据,下面是源码,大家使用的时候,将相应的.dll和.addins拷贝到C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Addins就可以了
有关垃圾清除的文章:发布小工具- 项目垃圾文件清理器(更新070920)
上篇文章: 手把手教你制作vs2005装饰
源码文件:/Files/jillzhang/SpitchCleaner.rar
效果图:
1.在项目的右键菜单增加 垃圾清理 子菜单
2.点击垃圾清除后的自定义输出
不明白的TX,可以下载源程序下去看看