本文介绍了为什么不是我的VSPackage的上下文菜单中的表现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我已经有一个包,我创造,我想一个菜单添加到代码窗口上下文菜单。 一个小的搜索后,我发现几篇文章,解释如何做到这一点。问题是,我无法得到它的工作.... 下面是我的声明在 vsct 文件: <按钮GUID =guidDALGeneratorPkgCmdSetID =cmdidDataFlow优先=0100型=按钮> ; <父GUID =guidSHLMainMenuID =IDM_VS_CTXT_CODEWIN/> < CommandFlag> DynamicVisibility< / CommandFlag> <字符串> <&的CommandName GT; cmdidDataFlow< /&的CommandName GT; < ButtonText>显示数据流和LT; / ButtonText> < /字符串> < /按钮> 和符号: < GuidSymbol NAME =guidDALGeneratorPkgCmdSetVALUE ={d3269a87-a721-49a5-800b-0464fbdfd313}> < IDSymbol NAME =MyMenuGroupVALUE =0x1020/> < IDSymbol NAME =cmdidDALGeneratorVALUE =0x0101/> < IDSymbol NAME =cmdidDataFlowVALUE =0x0102/> < / GuidSymbol> 和这里是我怎么加我的菜单我的套餐类: CommandID dataFlowCID =新CommandID(GuidList.guidDALGeneratorPkgCmdSet,(INT)PkgCmdIDList.cmdidDataFlow); OleMenuCommand dataFlowMenu =新OleMenuCommand(showDataFlow,dataFlowCID); dataFlowMenu.BeforeQueryStatus + =新的EventHandler(dataFlowMenu_BeforeQueryStatus); mcs.AddCommand(dataFlowMenu); 我在做什么错在这里?我一定会错过一些事情,因为几乎每一个样品(等主题回答)建议增加一个菜单中包的方式..... 我曾尝试 请一组第一再加入我的菜单在该组中:没有工作 检查,如果我使用正确的GUID(用的此招) 使用 IDG_VS_MENU_CONTEXTMENUS 而不是 IDM_VS_CTXT_CODEWIN (看看这个帖子后:的使用VSX你如何创建命令的子菜单?) 给同一母公司的菜单中实际工作到第二个菜单,仍然没有显示.... 关于我的问题... $ b很多不成功的谷歌搜索 $ b 此外,你可以看到我使用 BeforeQueryStatus 事件,但它永远不会被解雇了... 解决方案 审判的上下文菜单必须添加到一组是上下文菜单中显示它...其语法我花了几天并确定错误。 我创建了一个新的VSPackage的扩建工程则更新了我的VSTS文件,如下所示创建上面显示的上下文菜单: <命令包=guidVSPackage2Pkg> <组> <组GUID =guidVSPackage2CmdSetID =MyMenuGroup优先=为0x0600> <父GUID =guidSHLMainMenuID =IDM_VS_CTXT_CODEWIN/> < /组> <组GUID =guidVSPackage2CmdSetID =SubMenuGroup优先=0x0602> <父GUID =guidVSPackage2CmdSetID =子菜单/> < /组> < /组> <菜单和GT; <菜单GUID =guidVSPackage2CmdSetID =子菜单优先=0x0200TYPE =菜单> <父GUID =guidVSPackage2CmdSetID =MyMenuGroup/> <字符串> < ButtonText>测试上下文菜单< / ButtonText> < /字符串> < /菜单> < /菜单> <钮扣及GT; <按钮GUID =guidVSPackage2CmdSetID =cmdidMyCommand优先=0100型=按钮> <父GUID =guidVSPackage2CmdSetID =SubMenuGroup/> <图标GUID =guidImagesID =bmpPic1/> <字符串> < ButtonText>右键菜单按钮和LT; / ButtonText> < /字符串> < /按钮> < /按钮> <&位图GT; <位图GUID =guidImages的href =Resources\Images.pngusedList =bmpPic1,bmpPic2,bmpPicSearch,bmpPicX,bmpPicArrows/> < /位图> < /命令> <符号和GT; <! - 这是包GUID。 - > < GuidSymbol NAME =guidVSPackage2PkgVALUE ={1fde2aca-f1c8-4fbc-abd1-58861d8b9520}/> <! - 这是用于组的GUID的菜单命令一起 - > < GuidSymbol NAME =guidVSPackage2CmdSetVALUE ={9cfc9dda-a054-4ff2-8c85-e6d2bff04874}> < IDSymbol NAME =子菜单值=0x1001/> < IDSymbol NAME =SubMenuGroupVALUE =0×1000/> < IDSymbol NAME =MyMenuGroupVALUE =0x1020/> < IDSymbol NAME =cmdidMyCommand值=0100/> < / GuidSymbol> < GuidSymbol NAME =guidImagesVALUE ={b77d6bb1-566b-4ecb-a99f-9f99325ffd65}> < IDSymbol NAME =bmpPic1值=1/> < IDSymbol NAME =bmpPic2VALUE =2/> < IDSymbol NAME =bmpPicSearchVALUE =3/> < IDSymbol NAME =bmpPicXVALUE =4/> < IDSymbol NAME =bmpPicArrowsVALUE =5/> < IDSymbol NAME =bmpPicStrikethroughVALUE =6/> < / GuidSymbol> < /符号> I already have a package that I created, and I'd like to add a menu to the Code Window context menu.After a little search I found several articles explaining how to do it. The problem is, I can't get it work....Here are my declarations in the vsct file: <Button guid="guidDALGeneratorPkgCmdSet" id="cmdidDataFlow" priority="0x0100" type="Button"> <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/> <CommandFlag>DynamicVisibility</CommandFlag> <Strings> <CommandName>cmdidDataFlow</CommandName> <ButtonText>Show data flow</ButtonText> </Strings> </Button>and the symbols:<GuidSymbol name="guidDALGeneratorPkgCmdSet" value="{d3269a87-a721-49a5-800b-0464fbdfd313}"> <IDSymbol name="MyMenuGroup" value="0x1020" /> <IDSymbol name="cmdidDALGenerator" value="0x0101" /> <IDSymbol name="cmdidDataFlow" value="0x0102" /></GuidSymbol>and here is how I add my menu in my Package class:CommandID dataFlowCID = new CommandID(GuidList.guidDALGeneratorPkgCmdSet, (int)PkgCmdIDList.cmdidDataFlow);OleMenuCommand dataFlowMenu = new OleMenuCommand(showDataFlow, dataFlowCID);dataFlowMenu.BeforeQueryStatus += new EventHandler(dataFlowMenu_BeforeQueryStatus);mcs.AddCommand(dataFlowMenu);What am I doing wrong here? I must miss something because nearly every sample (and SO answer on the subject) suggests to add a menu that way in a package.....What I have tried:make a group first then add my menu in that group: didn't workcheck if I use the right GUID (with this trick)use IDG_VS_MENU_CONTEXTMENUS instead of IDM_VS_CTXT_CODEWIN (after a look at this post: Using vsx how do you create a sub menu with commands?)give the same parent as the menu that actually works to the second menu, still not showing....a lot of unsuccessful googling about my problem...Also as you can see I use the BeforeQueryStatus event, but it never gets fired... 解决方案 A context menu must be added to a group that is on the context menu for it to be displayed ... The syntax for this took me a couple days of trial and error to determine.I created a new VSPackage extension project then updated my VSTS file as follows to create the context menu shown above:<Commands package="guidVSPackage2Pkg"> <Groups> <Group guid="guidVSPackage2CmdSet" id="MyMenuGroup" priority="0x0600"> <Parent guid="guidSHLMainMenu" id="IDM_VS_CTXT_CODEWIN"/> </Group> <Group guid="guidVSPackage2CmdSet" id="SubMenuGroup" priority="0x0602"> <Parent guid="guidVSPackage2CmdSet" id="SubMenu" /> </Group> </Groups> <Menus> <Menu guid="guidVSPackage2CmdSet" id="SubMenu" priority="0x0200" type="Menu"> <Parent guid="guidVSPackage2CmdSet" id="MyMenuGroup" /> <Strings> <ButtonText>Test Context Menu</ButtonText> </Strings> </Menu> </Menus> <Buttons> <Button guid="guidVSPackage2CmdSet" id="cmdidMyCommand" priority="0x0100" type="Button"> <Parent guid="guidVSPackage2CmdSet" id="SubMenuGroup" /> <Icon guid="guidImages" id="bmpPic1" /> <Strings> <ButtonText>Context Menu Button</ButtonText> </Strings> </Button> </Buttons> <Bitmaps> <Bitmap guid="guidImages" href="Resources\Images.png" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows"/> </Bitmaps> </Commands> <Symbols> <!-- This is the package guid. --> <GuidSymbol name="guidVSPackage2Pkg" value="{1fde2aca-f1c8-4fbc-abd1-58861d8b9520}" /> <!-- This is the guid used to group the menu commands together --> <GuidSymbol name="guidVSPackage2CmdSet" value="{9cfc9dda-a054-4ff2-8c85-e6d2bff04874}"> <IDSymbol name="SubMenu" value="0x1001"/> <IDSymbol name="SubMenuGroup" value="0x1000"/> <IDSymbol name="MyMenuGroup" value="0x1020" /> <IDSymbol name="cmdidMyCommand" value="0x0100" /> </GuidSymbol> <GuidSymbol name="guidImages" value="{b77d6bb1-566b-4ecb-a99f-9f99325ffd65}" > <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> 这篇关于为什么不是我的VSPackage的上下文菜单中的表现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-23 21:46