private void Insert(SnapinNode parent, IntPtr nextHScopeItem) { GetImageIndices(); Snapin.EnsureImages(); IConsoleNameSpace2 ns = Snapin.ConsoleNamespace; ScopeDataItem item = new ScopeDataItem(); item.Mask = (uint)ScopeDataItemFlags.Str | (uint)ScopeDataItemFlags.Param | (uint)ScopeDataItemFlags.Next | (uint)ScopeDataItemFlags.Image | (uint)ScopeDataItemFlags.OpenImage | (uint)ScopeDataItemFlags.Children; item.Image = m_closedImageIndex; item.OpenImage = m_openImageIndex; item.RelativeId = nextHScopeItem; item.DisplayName = (IntPtr)(-1); item.Param = Cookie; item.Children = HasChildren() ? 1 : 0; // Expand the parent node before adding the child. ns.Expand(parent.HScopeItem); ns.InsertItem(ref item); HScopeItem = item.Id; m_parentHScopeItem = parent.HScopeItem; m_parentNode = parent; }
public void ImageChanged() { // Only try to update if the item has already been inserted and the images have changed. if (GetImageIndices() && HScopeItem != IntPtr.Zero) { ScopeDataItem item = new ScopeDataItem(); item.Id = HScopeItem; item.Mask = (uint)ScopeDataItemFlags.Image | (uint)ScopeDataItemFlags.OpenImage; item.Image = m_closedImageIndex; item.OpenImage = m_openImageIndex; IConsoleNameSpace2 ns = Snapin.ConsoleNamespace; ns.SetItem(ref item); // If this node is currently shown in the result view also update all the result images. // There is no correlation between a scope node and a result node, so all result nodes must // be checked. if (m_snapin.CurrentScopeNode == m_parentNode) { ResultNode parentResult = m_parentNode as ResultNode; if (parentResult != null) { parentResult.UpdateResultImages(); } } } }
}// SetControlbar //------------------------------------------------- // ControlbarNotify // // This function is called whenever one of our added // buttons on the toolbar is click //------------------------------------------------- public int ControlbarNotify(uint aevent, int arg, int param) { // If they clicked a button...... if (aevent == MMCN.BTN_CLICK) { // Query the Console interface we have for the namespace IConsoleNameSpace2 ConsoleNameSpace = (IConsoleNameSpace2)m_ucsole; // If they clicked our button we added // (This check is unnecessary since we only added one button if (param == 1) { // We want to open up the tree and center on the black icon. // We'll expand the root node for kicks... // ConsoleNameSpace.Expand((uint)m_Nodes[0].HScopeItem); // Now we'll expand each parent node for this guy // ConsoleNameSpace.Expand((uint)m_Nodes[1].HScopeItem); // Now let's set the focus on the black node // m_ucsole.SelectScopeItem(m_Nodes[3].HScopeItem); } } // Else we don't handle the event else { return(HRESULT.S_FALSE); } return(HRESULT.S_OK); }// ControlbarNotify
//------------------------------------------------- // CData - Constructor // // The constructor is responsible for constructing // the nodes that will be displayed in the snapin //------------------------------------------------- public CData() { if (m_rn != null) { throw new Exception(CResourceStore.GetString("CData::OnlyOneInstanceofSnapin")); } // First, null out all the member variables m_Component = new ArrayList(); m_ucsole = null; m_ucsoleNameSpace = null; m_rn = new CRootNode(); // Register ourselves with the Node Manager CNodeManager.Data = this; // Let's generate our own computer node CNodeManager.Init(); CNodeManager.RootNodeCookie = CNodeManager.AddNode(ref m_rn); }// CData
protected void ReplaceChildNode(SnapinNode node, SnapinNode newNode) { // Get information about the old node. IntPtr nextHScopeItem; IntPtr cookie; IConsoleNameSpace2 ns = Snapin.ConsoleNamespace; ns.GetNextItem(node.HScopeItem, out nextHScopeItem, out cookie); DeleteChildNode(node); if (nextHScopeItem != IntPtr.Zero) { InsertChildNode(newNode, nextHScopeItem); } else { InsertChildNode(newNode); } }
}// CData //------------------------------------------------- // Initialize // // This function is responsible for recieving the // MMC Console interface, and I also have it inserting // all the images MMC will need to display the snapin //------------------------------------------------- public void Initialize(Object pUnknown) { try { m_ucsole = (IConsole2)pUnknown; m_ucsoleNameSpace = (IConsoleNameSpace2)pUnknown; } catch (Exception) { // If this fails, it's because we're not on MMC 1.2 or later MessageBox(0, CResourceStore.GetString("CData:RequireVersionofMMC"), CResourceStore.GetString("CData:RequireVersionofMMCTitle"), MB.ICONEXCLAMATION); return; } CNodeManager.Console = m_ucsole; IntPtr hWnd; m_ucsole.GetMainWindow(out hWnd); CNodeManager.MMChWnd = hWnd; CNodeManager.CNamespace = m_ucsoleNameSpace; // Now we'll add the images we need for the snapin IImageList il = null; m_ucsole.QueryScopeImageList(out il); // ALL icons that need to be displayed in the lefthand pane MUST be // 'registered' here if (il != null) { il.ImageListSetIcon(CResourceStore.GetHIcon("NETappicon_ico"), CResourceStore.GetIconCookie("NETappicon_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("mycomputer_ico"), CResourceStore.GetIconCookie("mycomputer_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("configassemblies_ico"), CResourceStore.GetIconCookie("configassemblies_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("enterprisepolicy_ico"), CResourceStore.GetIconCookie("enterprisepolicy_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("machinepolicy_ico"), CResourceStore.GetIconCookie("machinepolicy_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("userpolicy_ico"), CResourceStore.GetIconCookie("userpolicy_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("codegroups_ico"), CResourceStore.GetIconCookie("codegroups_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("singlecodegroup_ico"), CResourceStore.GetIconCookie("singlecodegroup_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("customcodegroup_ico"), CResourceStore.GetIconCookie("customcodegroup_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("permissionsets_ico"), CResourceStore.GetIconCookie("permissionsets_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("permissionset_ico"), CResourceStore.GetIconCookie("permissionset_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("policyassemblies_ico"), CResourceStore.GetIconCookie("policyassemblies_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("assemblies_ico"), CResourceStore.GetIconCookie("assemblies_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("sharedassemblies_ico"), CResourceStore.GetIconCookie("sharedassemblies_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("remoting_ico"), CResourceStore.GetIconCookie("remoting_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("security_ico"), CResourceStore.GetIconCookie("security_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("applications_ico"), CResourceStore.GetIconCookie("applications_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("application_ico"), CResourceStore.GetIconCookie("application_ico")); il.ImageListSetIcon(CResourceStore.GetHIcon("readonlypolicy_ico"), CResourceStore.GetIconCookie("readonlypolicy_ico")); } }// Initialize
/// <summary> /// Extend node in data with this Snap-In /// </summary> /// <param name="data">IDataObject of node to extend</param> /// <param name="cns">MMC console namespace</param> /// <param name="hScope">HScopeItem for this Snap-In's root node</param> public void OnExtend(System.Runtime.InteropServices.ComTypes.IDataObject data, ref IConsoleNameSpace2 cns, int hScope) { this.RootNode.OnExpand(ref cns, hScope); }
/// <summary> /// Override MMCN_EXPAND event handler for extending another /// Snap-In /// </summary> /// <param name="dataInterface"></param> /// <param name="consoleNamespace"></param> /// <param name="hScope"></param> public override void OnExpand(System.Runtime.InteropServices.ComTypes.IDataObject dataInterface, ref IConsoleNameSpace2 consoleNamespace, int hScope) { //if (IsDataObject(dataInterface)) //{ // base.OnExpand(dataInterface, ref consoleNamespace, hScope); //} //else //{ // OnExtend(dataInterface, ref consoleNamespace, hScope); //} this.RootNode.HScopeItem = -1; //this.RootNode.OnExpand(ref consoleNamespace, hScope); this.RootNode.Expand(ref consoleNamespace, hScope); }