vsct架构说明: msdn查看
某些 VSCT 元素是可选的。 如果 Parent 将暗示 Group_Undefined:0,未指定参数。 如果 Icon 将暗示 guidOfficeIcon:msotcidNoIcon,未指定参数。 定义的快捷键后,模拟,这是通常未使用,是可选的。
通过指定的位置中的位图条,可能会在编译时嵌入位图项 href 参数。 位图条在合并过程中复制而不是从该 DLL 的资源中提取。 当 href 未提供参数, usedList 参数将成为可选的并且所有插槽的位图条都被都视为已使用。
通过使用符号名称,必须定义所有 GUID 和 ID 值。 标头文件中或在 VSCT < 符号 > 部分中,可以定义这些名称。 符号名称必须是本地的 < 包括 > 元素,通过包括或由 < Extern > 元素引用。 符号名称从它遵循简单模式,如果 < Extern > 元素中指定的标头文件导入 #define 符号值。 值可能是另一个符号,只要以前定义该符号。 GUID 定义必须遵循 OLE 或 c + + 格式。 ID 值可能是十进制数字或十六进制数以 0x 开头,如以下各行中所示:
可以使用 XML 注释,但往返的图形用户界面 (GUI) 工具可能会放弃它们。 保证 < 批注 > 元素的内容都将保留,与格式无关。
开始吧,这也是自学的关键。所以列出来了。 这里我找到了CommandTable,里面有KeyBindings
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema" >
<Extern>... </Extern>
<Include>... </Include>
<Define>... </Define>
<Commands>... </Commands>
<CommandPlacements>... </CommandPlacements>
<VisibilityConstraints>... </VisibilityConstraints>
<KeyBindings>... </KeyBindings>
<UsedCommands... </UsedCommands>
<Symbols>... </Symbols>
</CommandTable>
KeyBinding:查看

====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
===垃圾=====推酷========天天抓我文章,好不要脸====================
<KeyBindings> <KeyBinding guid="<name of command set>" id="<name of command id>" editor="guidVSStd97" key1="1" mod1="CONTROL"/> </KeyBindings>
mod1 属性设为 Control, ,Alt, ,或 Shift。
如果您的键盘快捷方式需要两个以上的键,则设置 mod2 和 key2 属性
若要使此命令可用在 Visual Studio 编辑器中,将设置 editor 属性设为 guidVSStd97。
若要使该命令仅适用于自定义编辑器,比如你新建Visual Studio Package 模板时候,就会在<Symbols>下的<GuidSymbol> 生成个name以editorfactory结尾的自定义编辑器名字。
你只要设置KeyBinding的editor特性的值改一下为你自定义的即可,那么这个快捷键就是作用于你自定义编辑器的。
如果接着上篇的博客项目写,打开csvt文件
添加子菜单:
添加ID
<GuidSymbol name="guidAyCommandPackageCmdSet" value="{206b5d97-fba4-4223-9342-08cc19cd3a19}">
<IDSymbol name="MyMenuGroup" value="0x1020" />
<IDSymbol name="AyCommandId" value="0x0100" />
<IDSymbol name="TopLevelMenu" value="0x1021" />
<IDSymbol name="SubMenu" value="0x1100"/>
<IDSymbol name="SubMenuGroup" value="0x1150"/>
<IDSymbol name="cmdidTestSubCommand" value="0x0105"/>
</GuidSymbol>
找到Menus节点
<Menu guid="guidAyCommandPackageCmdSet" id="SubMenu" priority="0x0100" type="Menu">
<Parent guid="guidAyCommandPackageCmdSet" id="MyMenuGroup"/>
<Strings>
<ButtonText>Sub Menu</ButtonText>
<CommandName>Sub Menu</CommandName>
</Strings></Menu>
创建一个子分组
<Group guid="guidAyCommandPackageCmdSet" id="SubMenuGroup" priority="0x0000">
<Parent guid="guidAyCommandPackageCmdSet" id="SubMenu"/>
</Group>
创建一个命令按钮
<Button guid="guidAyCommandPackageCmdSet" id="cmdidTestSubCommand" priority="0x0000" type="Button">
<Parent guid="guidAyCommandPackageCmdSet" id="SubMenuGroup" />
<Icon guid="guidImages" id="bmpPic2" />
<Strings>
<CommandName>cmdidTestSubCommand</CommandName>
<ButtonText>Test Sub Command</ButtonText>
</Strings>
</Button>
运行,安装插件,效果

添加命令事件
打开AyCommand.cs文件
添加一个命令ID
public const int cmdidTestSubCmd = 0x105;
然后构造函数加入命令,并绑定指定的处理
/// <summary>
/// Command ID.
/// </summary>
public const int CommandId = 0x0100;
public const int cmdidTestSubCmd = 0x105;
/// <summary>
/// Command menu group (command set GUID).
/// </summary>
public static readonly Guid CommandSet = new Guid("206b5d97-fba4-4223-9342-08cc19cd3a19");
/// <summary>
/// VS Package that provides this command, not null.
/// </summary>
private readonly Package package;
/// <summary>
/// Initializes a new instance of the <see cref="AyCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
private AyCommand(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
commandService.AddCommand(menuItem);
CommandID subCommandID = new CommandID(CommandSet, cmdidTestSubCmd);
MenuCommand subItem = new MenuCommand(
new EventHandler(SubItemCallback), subCommandID);
commandService.AddCommand(subItem);
}
}
private void SubItemCallback(object sender, EventArgs e)
{
IVsUIShell uiShell = (IVsUIShell)this.ServiceProvider.GetService(
typeof(SVsUIShell));
Guid clsid = Guid.Empty;
int result;
uiShell.ShowMessageBox(
0,
ref clsid,
"AyCommand",
string.Format(CultureInfo.CurrentCulture,
"Inside AyCommand.SubItemCallback()",
this.ToString()),
string.Empty,
0,
OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
OLEMSGICON.OLEMSGICON_INFO,
0,
out result);
}
编译后,先卸载,后安装,然后单击子菜单

绑定快捷键:
键值:
ESC键VK_ESCAPE (27)
回车键:VK_RETURN (13)
TAB键:VK_TAB (9)
Caps Lock键:VK_CAPITAL (20)
Shift键:VK_SHIFT (16)
Ctrl键:VK_CONTROL (17)
Alt键:VK_MENU (18)
空格键:VK_SPACE (32)
退格键:VK_BACK (8)
左徽标键:VK_LWIN (91)
右徽标键:VK_RWIN (92)
鼠标右键快捷键:VK_APPS (93)
Insert键:VK_INSERT (45)
Home键:VK_HOME (36)
Page Up:VK_PRIOR (33)
PageDown:VK_NEXT (34)
End键:VK_END (35)
Delete键:VK_DELETE (46)
方向键(←):VK_LEFT (37)
方向键(↑):VK_UP (38)
方向键(→):VK_RIGHT (39)
方向键(↓):VK_DOWN (40)
F1键:VK_F1 (112)
F2键:VK_F2 (113)
F3键:VK_F3 (114)
F4键:VK_F4 (115)
F5键:VK_F5 (116)
F6键:VK_F6 (117)
F7键:VK_F7 (118)
F8键:VK_F8 (119)
F9键:VK_F9 (120)
F10键:VK_F10 (121)
F11键:VK_F11 (122)
F12键:VK_F12 (123)
Num Lock键:VK_NUMLOCK (144)
小键盘0:VK_NUMPAD0 (96)
小键盘1:VK_NUMPAD1 (97)
小键盘2:VK_NUMPAD2 (98)
小键盘3:VK_NUMPAD3 (99)
小键盘4:VK_NUMPAD4 (100)
小键盘5:VK_NUMPAD5 (101)
小键盘6:VK_NUMPAD6 (102)
小键盘7:VK_NUMPAD7 (103)
小键盘8:VK_NUMPAD8 (104)
小键盘9:VK_NUMPAD9 (105)
小键盘。:VK_DECIMAL (110)
小键盘*:VK_MULTIPLY (106)
小键盘+:VK_ADD (107)
小键盘-:VK_SUBTRACT (109)
小键盘/:VK_DIVIDE (111)
Pause Break键:VK_PAUSE (19)
Scroll Lock键:VK_SCROLL (145)
增加快捷键

<KeyBindings>
<KeyBinding guid="guidAyCommandPackageCmdSet" id="AyCommandId" editor="guidVSStd97" key1="4" mod1="CONTROL" mod2="CONTROL" key2="VK_F1"/>
<KeyBinding guid="guidAyCommandPackageCmdSet" id="cmdidTestSubCommand" editor="guidVSStd97" key1="2" mod1="CONTROL" />
</KeyBindings>
OK:下面我们来练习一下,我需要在Sub Menu菜单下,加一个记事本命令,通过Ctrl+J+S打开
代码如下:
<?xml version="1.0" encoding="utf-8"?>
<CommandTable xmlns="http://schemas.microsoft.com/VisualStudio/2005-10-18/CommandTable" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- This is the file that defines the actual layout and type of the commands.
It is divided in different sections (e.g. command definition, command
placement, ...), with each defining a specific set of properties.
See the comment before each section for more details about how to
use it. -->
<!-- The VSCT compiler (the tool that translates this file into the binary
format that VisualStudio will consume) has the ability to run a preprocessor
on the vsct file; this preprocessor is (usually) the C++ preprocessor, so
it is possible to define includes and macros with the same syntax used
in C++ files. Using this ability of the compiler here, we include some files
defining some of the constants that we will use inside the file. -->
<!--This is the file that defines the IDs for all the commands exposed by VisualStudio. -->
<Extern href="stdidcmd.h"/>
<!--This header contains the command ids for the menus provided by the shell. -->
<Extern href="vsshlids.h"/>
<!--The Commands section is where commands, menus, and menu groups are defined.
This section uses a Guid to identify the package that provides the command defined inside it. -->
<Commands package="guidAyCommandPackage">
<!-- Inside this section we have different sub-sections: one for the menus, another
for the menu groups, one for the buttons (the actual commands), one for the combos
and the last one for the bitmaps used. Each element is identified by a command id that
is a unique pair of guid and numeric identifier; the guid part of the identifier is usually
called "command set" and is used to group different command inside a logically related
group; your package should define its own command set in order to avoid collisions
with command ids defined by other packages. -->
<Menus>
<Menu guid="guidAyCommandPackageCmdSet" id="TopLevelMenu" priority="0x700" type="Menu">
<Parent guid="guidSHLMainMenu"
id="IDG_VS_MM_TOOLSADDINS" />
<Strings>
<ButtonText>TestMenu</ButtonText>
<CommandName>TestMenu</CommandName>
</Strings>
</Menu>
<Menu guid="guidAyCommandPackageCmdSet" id="SubMenu" priority="0x0100" type="Menu">
<Parent guid="guidAyCommandPackageCmdSet" id="MyMenuGroup"/>
<Strings>
<ButtonText>Sub Menu</ButtonText>
<CommandName>Sub Menu</CommandName>
</Strings>
</Menu>
</Menus>
<!-- In this section you can define new menu groups. A menu group is a container for
other menus or buttons (commands); from a visual point of view you can see the
group as the part of a menu contained between two lines. The parent of a group
must be a menu. -->
<Groups>
<Group guid="guidAyCommandPackageCmdSet" id="MyMenuGroup" priority="0x0600">
<Parent guid="guidAyCommandPackageCmdSet" id="TopLevelMenu"/>
</Group>
<Group guid="guidAyCommandPackageCmdSet" id="SubMenuGroup" priority="0x0000">
<Parent guid="guidAyCommandPackageCmdSet" id="SubMenu"/>
</Group>
</Groups>
<!--Buttons section. -->
<!--This section defines the elements the user can interact with, like a menu command or a button
or combo box in a toolbar. -->
<Buttons>
<!--To define a menu group you have to specify its ID, the parent menu and its display priority.
The command is visible and enabled by default. If you need to change the visibility, status, etc, you can use
the CommandFlag node.
You can add more than one CommandFlag node e.g.:
<CommandFlag>DefaultInvisible</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
If you do not want an image next to your command, remove the Icon node /> -->
<Button guid="guidAyCommandPackageCmdSet" id="AyCommandId" priority="0x0100" type="Button">
<Parent guid="guidAyCommandPackageCmdSet" id="MyMenuGroup" />
<Icon guid="guidImages" id="bmpPic1" />
<Strings>
<CommandName>AyCommandId</CommandName>
<ButtonText>开始 AyCommand3</ButtonText>
</Strings>
</Button>
<Button guid="guidAyCommandPackageCmdSet" id="cmdidTestSubCommand" priority="0x0000" type="Button">
<Parent guid="guidAyCommandPackageCmdSet" id="SubMenuGroup" />
<Icon guid="guidImages" id="bmpPic2" />
<Strings>
<CommandName>cmdidTestSubCommand</CommandName>
<ButtonText>Test Sub Command</ButtonText>
</Strings>
</Button>
<Button guid="guidAyCommandPackageCmdSet" id="cmdidNotepadCommand" priority="0x0001" type="Button">
<Parent guid="guidAyCommandPackageCmdSet" id="SubMenuGroup" />
<Icon guid="guidImages" id="bmpPic2" />
<Strings>
<CommandName>cmdidNotepadCommand</CommandName>
<ButtonText>打开记事本</ButtonText>
</Strings>
</Button>
</Buttons>
<!--The bitmaps section is used to define the bitmaps that are used for the commands.-->
<Bitmaps>
<!-- The bitmap id is defined in a way that is a little bit different from the others:
the declaration starts with a guid for the bitmap strip, then there is the resource id of the
bitmap strip containing the bitmaps and then there are the numeric ids of the elements used
inside a button definition. An important aspect of this declaration is that the element id
must be the actual index (1-based) of the bitmap inside the bitmap strip. -->
<Bitmap guid="guidImages" href="Resources\AyCommand.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows, bmpPicStrikethrough"/>
</Bitmaps>
</Commands>
<KeyBindings>
<KeyBinding guid="guidAyCommandPackageCmdSet" id="AyCommandId" editor="guidVSStd97" key1="4" mod1="CONTROL" mod2="CONTROL" key2="VK_F1"/>
<KeyBinding guid="guidAyCommandPackageCmdSet" id="cmdidTestSubCommand" editor="guidVSStd97" key1="2" mod1="CONTROL" />
<KeyBinding guid="guidAyCommandPackageCmdSet" id="cmdidNotepadCommand" editor="guidVSStd97" key1="J" mod1="CONTROL" mod2="CONTROL" key2="S"/>
</KeyBindings>
<Symbols>
<!-- This is the package guid. -->
<GuidSymbol name="guidAyCommandPackage" value="{75a23647-9848-418c-8800-6a144465d398}" >
</GuidSymbol>
<!-- This is the guid used to group the menu commands together -->
<GuidSymbol name="guidAyCommandPackageCmdSet" value="{206b5d97-fba4-4223-9342-08cc19cd3a19}">
<IDSymbol name="MyMenuGroup" value="0x1020" />
<IDSymbol name="AyCommandId" value="0x0100" />
<IDSymbol name="TopLevelMenu" value="0x1021" />
<IDSymbol name="SubMenu" value="0x1100"/>
<IDSymbol name="SubMenuGroup" value="0x1150"/>
<IDSymbol name="cmdidTestSubCommand" value="0x0105"/>
<IDSymbol name="cmdidNotepadCommand" value="0x0106"/>
</GuidSymbol>
<GuidSymbol name="guidImages" value="{65c53e13-8b40-4219-a89f-71b1b10b97d3}" >
<IDSymbol name="bmpPic1" value="1" />
<IDSymbol name="bmpPic2" value="2" />
<IDSymbol name="bmpPicSearch" value="3" />
<IDSymbol name="bmpPicX" value="4" />
<IDSymbol name="bmpPicArrows" value="5" />
<IDSymbol name="bmpPicStrikethrough" value="6" />
</GuidSymbol>
</Symbols>
</CommandTable>
命令代码:
public const int CommandId = 0x0100;
public const int cmdidTestSubCmd = 0x105;
public const int cmdidNotepadCommand = 0x106;
/// <summary>
/// Command menu group (command set GUID).
/// </summary>
public static readonly Guid CommandSet = new Guid("206b5d97-fba4-4223-9342-08cc19cd3a19");
/// <summary>
/// VS Package that provides this command, not null.
/// </summary>
private readonly Package package;
/// <summary>
/// Initializes a new instance of the <see cref="AyCommand"/> class.
/// Adds our command handlers for menu (commands must exist in the command table file)
/// </summary>
/// <param name="package">Owner package, not null.</param>
private AyCommand(Package package)
{
if (package == null)
{
throw new ArgumentNullException("package");
}
this.package = package;
OleMenuCommandService commandService = this.ServiceProvider.GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
if (commandService != null)
{
var menuCommandID = new CommandID(CommandSet, CommandId);
var menuItem = new MenuCommand(this.MenuItemCallback, menuCommandID);
commandService.AddCommand(menuItem);
CommandID subCommandID = new CommandID(CommandSet, cmdidTestSubCmd);
MenuCommand subItem = new MenuCommand(
new EventHandler(SubItemCallback), subCommandID);
commandService.AddCommand(subItem);
CommandID notepadCommandID = new CommandID(CommandSet, cmdidNotepadCommand);
MenuCommand notepadItem = new MenuCommand(
new EventHandler(NotepadCallback), notepadCommandID);
commandService.AddCommand(notepadItem);
}
}
private void NotepadCallback(object sender, EventArgs e)
{
ThreadHelper.JoinableTaskFactory.RunAsync(async delegate
{
Process proc = new Process();
proc.StartInfo.FileName = "notepad.exe";
proc.Start();
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
});
}
最后一段代码,我找了很久的,终于异步解决了,缺点就是 支持vs2012以上的vs了。因为用到了async await
====================www.ayjs.net 杨洋 wpfui.com ayui ay aaronyang=======请不要转载谢谢了。=========
显示错误:
ShowError(_errorListProvider, TaskErrorCategory.Error, TaskPriority.High, "DNU completed with errors. Check the build output window for details.", hierarchyItem: null);
推荐您阅读更多有关于“vs2015,vsix开发,”的文章
额 本文暂时没人评论 来添加一个吧
发表评论