在LearnVSXNow系列译文的第6篇发布后,有个朋友问了这么一个问题:“如果我想将一个Package的UI元素放至另外一个第三方的Package的菜单下,你有什么好的建议吗?这个东西现在在困扰着我。”

     我们知道,可以把package的菜单放到Visual Studio提供的菜单下,这其实和把菜单放到第三方package的菜单下没有本质的区别,当然前提是你得知道第三方的这个package的commandset这个guid和包含的Group或Menu的id。从他的回复可以看出,这些guid和id他是知道的,那我们就以这个作为前提,来看一下如何将自己的菜单项放到别人的菜单下。

     由于我手头上没有这个第三方的package,所以得先“造一个”出来:

<?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">
 
    <Extern href="stdidcmd.h"/>
 
    <Extern href="vsshlids.h"/>
 
    <Extern href="msobtnid.h"/>
 
    <Commands package="guidMenuPackagePkg">
 
        <Menus>
 
            <Menu guid="guidMenuPackageCmdSet" id="TopLevelMenu" priority="0x100" type="Menu">
                <Parent guid="guidSHLMainMenu" id="IDG_VS_MM_BUILDDEBUGRUN" />
                <Strings>
                    <ButtonText>Top Level Menu</ButtonText>
                    <CommandName>Top Level Menu</CommandName>
                </Strings>
            </Menu>
 
            <Menu guid="guidMenuPackageCmdSet" id="Child2Menu" priority="0x050" type="Menu">
                <Parent guid="guidMenuPackageCmdSet" id="TopLevelMenuGroup" />
                <Strings>
                    <ButtonText>child2</ButtonText>
                </Strings>
            </Menu>
 
        </Menus>
 
        <Groups>
            <Group guid="guidMenuPackageCmdSet" id="TopLevelMenuGroup" priority="0x0600">
                <Parent guid="guidMenuPackageCmdSet" id="TopLevelMenu"/>
            </Group>
            <Group guid="guidMenuPackageCmdSet" id="Child2MenuGroup" priority="0x0600">
                <Parent guid="guidMenuPackageCmdSet" id="Child2Menu"/>
            </Group>
        </Groups>
 
        <Buttons>            
 
            <Button guid="guidMenuPackageCmdSet" id="cmdidChild1Command" priority="0x0100" type="Button">
                <Parent guid="guidMenuPackageCmdSet" id="TopLevelMenuGroup" />
                <Icon guid="guidImages" id="bmpPic1" />
                <Strings>
                    <CommandName>cmdidMyCommand</CommandName>
                    <ButtonText>Sub Menu Command</ButtonText>
                </Strings>
            </Button>
 
            <Button guid="guidMenuPackageCmdSet" id="cmdidChild21Command" priority="0x0200" type="Button">
                <Parent guid="guidMenuPackageCmdSet" id="Child2MenuGroup" />
                <Icon guid="guidImages" id="bmpPic2" />
                <Strings>
                    <CommandName>cmdidChild21Command</CommandName>
                    <ButtonText>child 2 Sub Menu Command 1</ButtonText>
                </Strings>
            </Button>
 
            <Button guid="guidMenuPackageCmdSet" id="cmdidChild22Command" priority="0x0100" type="Button">
                <Parent guid="guidMenuPackageCmdSet" id="Child2MenuGroup" />
                <Icon guid="guidImages" id="bmpPic2" />
                <Strings>
                    <CommandName>cmdidChild22Command</CommandName>
                    <ButtonText>child 2 Sub Menu Command 2</ButtonText>
                </Strings>
            </Button>
        </Buttons>
 
        <Bitmaps>
            <Bitmap guid="guidImages" href="Resources\Images_32bit.bmp" usedList="bmpPic1, bmpPic2, bmpPicSearch, bmpPicX, bmpPicArrows"/>
        </Bitmaps>
 
    </Commands>
 
    <Symbols>
        <GuidSymbol name="guidMenuPackagePkg" value="{71568627-ddde-47f7-9ac6-ca2f82f1025c}" />
 
        <GuidSymbol name="guidMenuPackageCmdSet" value="{0215cb29-d60b-494c-b497-bfcaf0f12ab1}">
            <IDSymbol name="TopLevelMenu" value="0x1000" />
            <IDSymbol name="TopLevelMenuGroup" value="0x2000" />
            <IDSymbol name="Child2Menu" value="0x2100" />
            <IDSymbol name="Child2MenuGroup" value="0x2200" />
            <IDSymbol name="cmdidChild21Command" value="0x2201" />
            <IDSymbol name="cmdidChild22Command" value="0x2202" />
            <IDSymbol name="cmdidChild1Command" value="0x2300" />
        </GuidSymbol>
        <GuidSymbol name="guidImages" value="{3eb3ea0a-bf7f-41b4-8be7-273425f17ab0}" >
            <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" />
        </GuidSymbol>
    </Symbols>
</CommandTable>

相关文章:

  • 2021-05-20
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
  • 2021-11-30
  • 2022-12-23
猜你喜欢
  • 2021-08-19
  • 2022-12-23
  • 2021-12-14
  • 2021-12-25
  • 2022-12-23
  • 2021-04-19
相关资源
相似解决方案