MMC related programming interface MMC implements the following interfaces: IColumnData (new in MMC 1.2) IConsole2 IConsoleNameSpace2 IConsoleVerb IContextMenuCallback IContextMenuProvider IControlbar IDisplayHelp IHeaderCtrl2 (new in MMC 1.2) IImageList IMenuButton IPropertySheetCallback IPropertySheetProvider IRequiredExtensions IResultData IToolbar Snap-ins implements the following interfaces: IComponent IComponentData IEnumTASK IExtendContextMenu IExtendControlbar IExtendPropertySheet2 IExtendTaskPad IRequiredExtensions IResultDataCompare IResultDataCompareEx (new in MMC 1.2) IResultOwnerData ISnapinAbout ISnapinHelp2IComponent interface represents the results of the column on the right (result pane) in an object, the object is to use this interface MMC communication needs and the results column; IComponentData interface represents The object in the Scopet PANE (Scopet PANE) (these objects can be called node), the MMC needs to use this interface when communicating with objects in the directory bar; IEXTendContextMenu interface, whether the user right-click the node on the left ( Scope PANE ITEM or the Right Item, MMC pops up a default association menu, and MMC will use this interface to ask the object (Item), do you need to add your own menu item. IEXTendControlbar and IextendpropertySheet2 are also similar. IsnapINabout implements an interface on dialog boxes, MMC understands Snapin's version, description information, provider information, dialog icon through this interface, and is particularly important that MMC has obtained all nodes of Snapin through this interface. The default icon, the icon to modify the root node can also be provided to the MMC through this function getStaticFolderImage. For a detailed description, please refer to Platform SDK. Snapin does not need to implement all interfaces, SAMPLE only implemented: IComponent IComponentData IextendContextMenu IExtendControlbar iextendPropertySheet2 ISNAPINABOUT MMC ATL Implementation Support Class Introduction Samples Model ATL implements almost all interfaces, providing the default processing code. The code generated by ATL WIZZARD provides basic programming framework, and SNAPIN features depends on the overload of certain functions of CMYSNAPINDATA to modify the default behavior. In the above figure, the base class IExtendContextMenuimpl, IEXTendContextPropertySheet, which relies on several of CMYSNAPINDATA, but only because the line is too chaotic.
Snapin DLL Sample Generates STEP BY Step1, New ATL Project, if you need to use the MFC, you can use the wizzard option to support the MFC project named6; 2, "New ATL Object", select "MMC Snapin"; 3, name "mysnapin", and the "MMC Snapin" second property page, select IextendContextMenu, IextendControlbar, IextendPropertySheet, IsnapinAbout; and removing the support for persistence; 4, after determining, ATL Wizzard generated CMySnapin us, CCMySnapinComponent, CMySnapinData, CMySnapinAbout, CMySnapinPage ; 5, compile; then run MMC.exe, add a management unit "mysnapin", saving as mysnapin.msc; code introduction CMYSNAPIN implements IComponentData, IExtendContextMenu, IEXtendPropertySheet three interfaces. CMYSNAPINComponent implements IComponent, IextendContextMenu, IExtendControlbar, IExtendpropertySheet four interfaces, CMYSNAPINABOUT implements the ISNAPINABOUT interface. DLL exposes both CMYSNAPIN and CMYSNAPINABOUT to the outside. So MMC can find ISnapinAbout and IComponentData, IExtendContextMenu ,, IExtendPropertySheet three interfaces, and MMC objects created by CreateComponent CMySnapinComponent IComponentData method, which in turn provides CMySnapinComponent of IComponent, IExtendContextMenu, IExtendControlbar, IExtendPropertySheet four interfaces. As can be seen from the figure, the ATL interface implementation class implements the default behavior of the partial method, and then passes several important methods such as Notify, such as NOTINDATA objects, and continue to process. CMYSNAPINDATA inherits from CSNAPiniteMPL, CSNAPinItem IMPL implements a CSNAPinItem interface that defines all the behaviors of the ITEM object (the left node (Scope Pane Item). CMYSNAPIN creates CMYSNAPINDATA in the constructor as root point. All behaviors of an ITEM can modify the default behavior by overloading certain methods. For example, add a few child nodes below the root node, you can process MMCN_EXPAND messages in the overloaded Notify method.
MMC Snap-in Wizardmmc Snap-in Wizard in MSDN told MMC Snap-in FAQ: 1. How do I add a Toolbar Resource to the Snap-in Object? 2. How do I add menu items, Control Bar Buttons, and A Property Sheet To The Snap-In Object? 3. How do I Enumerate The child? 4. How do i add custom- ney Item type to the Snap-in Object? Please refer to MSDN for your own content The above method can make a complete function of Snapin. However, very unfortunately, ATL Wizzard is provided whether it is a menu, toolbar or property page is all Item common, whether Scope Item or Result Item. Especially when there are multiple different types of nodes, this is almost uncomfortable. How to generate a sub-node (Scope Item) on demand custom Item? After the code framework is generated in accordance with the above steps, run mysnapin.msc can see that there is only one root node, the name is mysnapin. Modify the name of this root point, only need to modify the const olechar * cmysnapindata :: m_szdisplay_name = OLESTR ("MySnapin") in mysnapin.cpp file; this line can be made. As mentioned earlier, the ATL puts the item abstraction into a CSNAPinitem interface, and the CSNAPiniteMimpl class implements most of the default behavior of this interface, so all Item should inherit from this class. Considering CMYSNAPINDATA as our root node, ATL has generated some code for us, from CMYSNAPINDATA inheritance is a better choice. (Recounted code actually only the initialization code in the CMYSNAPINDATA constructor, but the greatest advantage of CMYSNAPINDATA is to place a public implementation in the CMYSNAPINDATA class without the need for each Item class to implement one of the same code.) This article will inherit from the CMYSNAPINDATA class, as well as the CMYSNAPindata will be implemented as a base class, so we need another root point. Next, we will generate three primary sub-nodes, which are similar to "Services", "Event Viewer", "Account Management", and then regenerate into a secondary subtock in "Event Viewer" and "Account Management". Basically contain custom menus, attribute pages, toolbars, etc. Inherited from CMYSNAPINDATA, generating CiteMroot, CServicesContainer, CeventsContainer, CaccountsContainer. Note that in the mysnapin.h file, join a line of #include "test6.h". In CMYSNAPIN's constructor, we change the root node to Citemroot. In the Citemroot class, overload the Notify method, add the code to process MMCN_expand, which gives us the opportunity to add a child node (Scope Item).
case MMCN_EXPAND: {CComQIPtr
For each Snapin, there is a IImageList interface for use, MMC uses this icon list to save all the icons you need to use, and each item only needs to indicate the index of its icon list: m_scopedataItem.nimage = 2 m_scopedataItem.nopenImage = 2; But the icon in the Scope column is not loaded by the MMCN_ADD_IMAGES message, but must first load all the necessary icons in the initialize method of the CMYSNAPIN. Also, the above method does not work on the icon of root nodes. The modification of the icon of the root node must be modified by modifying the CMYSNAPINABOUT GetStaticFolderImage method. You can also add an icon to the About dialog box. How to modify the default display of the child node in the result column? Scope Item only displaced a name in the Result PANE. For example, when selecting "MySnapin", the default behavior is displayed in the Result PANE. Below we let the Event Viewer display more detailed information. MMCN_SHOW modified message in the Notify method CEventsContainer: case MMCN_SHOW: {CComQIPtr
4 and use HRESULT OnStart (Bool & BhandLled, CSnapinObjectRootBase * Pobj); HRESULT OnStop (Bool & BhandLled, CSNAPNObjectBase * Pobj); 5, if necessary, save the UpdateMenustate function to modify the menu status; how to add your own unique toolbar to a child node? Add the "Start" project to the Services project, "Stop" toolbar button. 1, add the toolbar to the resource, add button "Start", "Stop"; 2, use the macro begin_snapintoolbarid_map (cservice) SnapintoolBarid_Entry (idR_toolbar1) end_snapintoolbarid_map () to receive command messages. 3, if necessary, overload the UpdateToolbarbutton function modify the button status; Add a property page to the Account. 1. Overload the Notify method in the Caccount class. 2, in the processing method MMCN_SELECT Notify message: CComPtr