次の方法で共有


Working with Toolbars: Implementation Details

To add toolbars 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 TOOLBAR to create a new toolbar. 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 new toolbar control. Use this pointer to call the methods of the IToolbar interface associated with the new toolbar control.
    • Add bitmaps by calling IToolbar::AddBitmap. Call this method only once to add all the toolbar bitmaps at one time.
    • Fill an MMCBUTTON structure for each toolbar button that the snap-in adds and then add the buttons by calling IToolbar::AddButtons to add an array of buttons or IToolbar::InsertButton to add a single button.
  3. In the snap-in's implementation of ControlbarNotify, handle the toolbar-specific notification messages that MMC sends during calls to the ControlbarNotify method. There are three such notifications: MMCN_BTN_CLICK, 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 toolbar to the toolbar control (using IControlbar::Attach) during selection of an item and then detaching the toolbar (using IControlbar::Detach) during deselection of that item.
    • The MMCN_BTN_CLICK notification message is sent to the snap-in's ControlbarNotify implementation when a user clicks one of the snap-in's toolbar buttons. MMC sends this notification with the same command identifier (idCommand) that the snap-in assigned to the button in its MMCBUTTON structure when it added the button. The snap-in can process the command and then return S_OK.
  4. Implement a mechanism for setting the attributes of the toolbar buttons using the IToolbar::SetButtonState method.

Working with Toolbars and Menu Buttons: Interfaces

Extending a Primary Snap-in's Control Bar