我使用这个代码添加到代码窗口中的项目右键菜单:VS2008加载项添加到菜单
public void OnConnection(
object application,
ext_ConnectMode connectMode,
object addInInst,
ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
object[] contextGUIDS = new object[] { };
Command codeWindowCommand = null;
CommandBarControl codeWindowButton;
CommandBar codeCommandBar;
CommandBars commandBars;
try
{
codeWindowCommand = _applicationObject.Commands.Item(
_addInInstance.ProgID + "." + CODEWINDOW_COMMAND_NAME, 0);
}
catch
{
}
if (codeWindowCommand == null)
{
codeWindowCommand = _applicationObject.Commands.AddNamedCommand(
_addInInstance,
CODEWINDOW_COMMAND_NAME,
CODEWINDOW_COMMAND_NAME,
"Pastebin selected code",
true,
18,
ref contextGUIDS,
(int)vsCommandStatus.vsCommandStatusSupported +
(int)vsCommandStatus.vsCommandStatusEnabled);
}
commandBars = (CommandBars)_applicationObject.CommandBars;
codeCommandBar = commandBars["Code Window"];
codeWindowButton = (CommandBarControl)codeWindowCommand.AddControl(
codeCommandBar, codeCommandBar.Controls.Count + 1);
codeWindowButton.Caption = "Text for button";
codeWindowButton.TooltipText = "Tooltip for button";
}
和插件被设置为自动启动。但是每次运行VS2008时,它都会在菜单中添加另一个按钮,直到我完全删除插件。任何人都知道我如何解决这个问题
我会例如包装Command.AddControl()和后来的东西在一个如果只执行如果按钮不存在,但我似乎无法找到一种方法来检查这在API中?
我会勉强做一个短期修复,然后在我得到时间时深入研究这些信息。我能找到的大部分内容都是用这种叫做vb.net的可怕语言来处理的,这个语言并不是很有用,所以谢谢。 – ewanm89 2009-09-19 20:55:56
明天我会检查它的工作,或者我有时间的星期一,明天就这样去做。很多包装要做。 – ewanm89 2009-09-19 20:57:09
谢谢,这些链接与这一个很大的帮助:http://www.mztools.com/articles/2006/MZ2006014.aspx – ewanm89 2009-09-25 01:23:15