5

e.g. Consider the following code:

<Group guid="guidFirstCommandCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>

<Group guid="guidSecondCommandCmdSet" id="MyMenuGroup" priority="0x0600">
        <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>

Here, why do we need to define both GUID and ID? id="IDM_VS_MENU_TOOLS" refers to Tools menu in Visual Studio. What is the use of guid="guidSHLMainMenu"?

Also consider the following code:

  <Button guid="guidSecondCommandCmdSet" id="cmdidSecondCommand" priority="2" type="Button">
    <Parent guid="guidSecondCommandCmdSet" id="MyMenuGroup"/>
    <Icon guid="guidImages" id="bmpPic2"/>
    <Strings>
      <ButtonText>XXX Command</ButtonText>
    </Strings>
  </Button>

I understand that the button has the id called "cmdidSecondCommand", but where would the GUID of the button be used? We are already defining the Parent container of the button in the next element.

Shrey Baxi
  • 53
  • 5
  • 2
    The guid is replaced by the compiler by a Globally Unique ID. It ensures that your command set can never collide with another one that was created by a programmer that you don't know. – Hans Passant Feb 04 '16 at 13:25
  • 1
    If the GUID is globally unique, why is an additional ID required? – 3dGrabber Mar 14 '16 at 10:16

1 Answers1

5

A GUID is as the name implies a globally unique identifier in the form of {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}. An ID is a key (or identifier); which is used like a constant allowing to give descriptive names to numeric values.

Since the values behind an ID are not unique over all command sets (or image-strips), the GUID is used to put them into context... a combination of a guid and a numeric value is used to uniquely identify groups, menus, toolbars, buttons, images etc...

In the given example MyMenuGroup and IDM_VS_MENU_TOOLS could potentially have the same mumeric value, but the guids guidSecondCommandCmdSetand guidSHLMainMenu put them into context...

<Group guid="guidSecondCommandCmdSet" id="MyMenuGroup" priority="0x0600">
    <Parent guid="guidSHLMainMenu" id="IDM_VS_MENU_TOOLS"/>
</Group>

You need the GUID and the ID when you want to register Execute- and QueryStatus handlers for controls in your code, set an icon for a button, set elements into relation; for instance adding a group to a toolbar, or menu and so on...

Matze
  • 5,100
  • 6
  • 46
  • 69