Working with Menu Buttons: Implementation Details

To add menu buttons using IExtendControlBar

  1. Implement the IExtendControlbar interface and its two methods, SetControlBar and ControlbarNotify.

    The snap-in's IComponent implementation should implement and expose the IExtendControlbar interface.

  2. In the snap-in's implementation of SetControlBar:
    • Cache the IControlBar interface pointer that is passed into SetControlBar. Use this interface pointer to call the IControlBar methods.
    • Call IControlBar::Create with the nType parameter set to MENUBUTTON to create a new menu button. The pExtendControlbar parameter specifies the snap-in's IExtendControlbar interface associated with the control. The ppUnknown parameter will hold a pointer to the address of the IUnknown interface of the menu button control. Use this pointer to call the methods of the IMenuButton interface associated with the new control.
    • Add the menu button by calling IMenuButton::AddButton. The idCommand parameter specifies a snap-in-defined value that uniquely identifies the menu button to be added. The lpButtonText and lpTooltipText parameters point to the values of the button text and tooltip text, respectively.
  3. In the snap-in's implementation of ControlbarNotify, handle the menu button-specific notification messages that MMC sends during calls to the ControlbarNotify method. There are three such notifications: MMCN_MENU_BTNCLICK, MMCN_SELECT, and MMCN_DESELECT_ALL.
    • The MMCN_SELECT notification message is sent to the snap-in's ControlbarNotify method when an item is selected or deselected in either the scope pane or result pane. The snap-in can respond to this notification by attaching its menu button to the control (using IControlbar::Attach) and enabling the menu button (using IControlbar::SetButtonState) during selection of an item. During deselection of the item, the snap-in can again call IControlbar::SetButtonState, this time to disable the menu button and make it hidden.
    • The MMCN_MENU_BTNCLICK notification message is sent to the snap-in's ControlbarNotify implementation when a user clicks one of the snap-in's menu buttons. MMC sends this notification with a MENUBUTTONDATA structure that holds the same command identifier (idCommand) that the snap-in specified for the button when it added the button using IMenuButton::AddButton. The snap-in can process the command and then return S_OK.
  4. Implement a mechanism for setting the attributes of the menu buttons using the IMenuButton::SetButtonState method.

Related topics

Working with Toolbars and Menu Buttons: Interfaces
Extending a Primary Snap-in's Control Bar