次の方法で共有


Working with Toolbars and Menu Buttons

MMC creates it easy to use toolbars and menu buttons — two of the most frequently included features in today's applications. There are several interfaces related to these features, beginning with IControlbar. This interface allows for creating and manipulating a control bar to hold toolbars and other controls. This interface's methods include Create, which is used to create and return the requested control — either a toolbar or a drop-down menu. The other IControlbar methods are Attach, which associates a control with the control bar, and Detach, which breaks that association. You should also use these methods to display or hide a toolbar or menu button.

The IExtendControlbar interface enables a snap-in to add toolbars and menu buttons by using a callback interface, and has two methods. The first is SetControlBar, which gets a pointer to the IControlbar interface implemented by the console. The second method, ControlbarNotify, is the mechanism that allows the snap-in to respond to user actions such as mouse-button clicks. When the user causes an event, MMC sends a notification message to the snap-in. All notifications applicable to toolbars and menu buttons are listed in the documentation of the ControlbarNotify method.

The IToolbar interface is implemented by the console. It allows your snap-in to perform a variety of actions related to toolbars, including creating them, adding items to them, extending them, and that displays them. The AddBitmap method allows you to add images to the toolbar, and the AddButtons method provides a way to add an array of buttons to the toolbar. To add a single button, you can use the InsertButton method; to remove one, you can use the DeleteButton method. Finally, you can get an attribute of a button by using the GetButtonState method and set an attribute with the SetButtonState method.

The IMenuButton interface is also implemented by the console. The interface enables a snap-in to add menu buttons to the console's menu bar. MMC provides one menu bar per view; when a snap-in has the focus you can add one or more menu buttons for the view to this bar. These buttons are always added by appending them to the buttons already in the menu bar.

The IMenuButton interface has three methods. These methods allow you to add and set the attributes and states of menu buttons. The AddButton method enables you to add a button to the MMC menu bar for a particular view. The SetButton method can then be used to set the text attributes of a button in the menu bar. Finally, the SetButtonState method enables you to change the state of a menu button.

The last interface you have to consider when working with toolbars is IConsoleVerb. The verbs — which include cut, copy, paste, print, and others you would expect to see — are listed in the MMC_CONSOLE_VERB enumeration. You can determine the state of a verb by using the GetVerbState method; you can set the state with the SetVerbState method.

An extension snap-in can add toolbar buttons and menu buttons for node types that it does not own (that is, node types added by a primary snap-in). MMC always calls an extension snap-in's implementation of the IExtendControlbar::SetControlBar method if that snap-in implements the IExtendControlbar interface. The extension snap-in can use the IControlbar interface passed to it in SetControlBar to attach a toolbar or menu button control to a primary snap-in's control bar and then add buttons and manipulate them using the IToolbar or IMenuButton interface.

Be aware that the extension snap-in manipulates a primary snap-in's control bar in the same way that the primary snap-in does. That is, programmatically the extension "owns" the control, so it need not consider any other snap-ins when dealing with issues such as the index values of bitmaps placed on the toolbar, or the command ID of items placed in a menu button. The only requirement for the extension snap-in is that it explicitly register itself as being a toolbar extension for items (scope or result) of the particular node type it wants to extend. For more information, see Extending a Primary Snap-in's Control Bar.

Working with Toolbars and Menu Buttons: Interfaces

Working with Toolbars: Implementation Details

Extending a Primary Snap-in's Control Bar