home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------
- // CData.cs
- //
- // This implements the IComponentData, ISnapinHelp2, and IExtendPropertySheet
- // MMC interfaces.
- //
- // Its GUID is {94B9D51F-C874-4da0-BC13-FDA94CBF72DE}
- //-------------------------------------------------------------
-
- using System;
- using System.Runtime.InteropServices;
-
- namespace Microsoft.SampleMMC
- {
- [Guid("94B9D51F-C874-4da0-BC13-FDA94CBF72DE")]
- public class CData : IComponentData, ISnapinHelp2, IExtendPropertySheet
- {
- private CComponent m_Component; // The IComponent object
- private IConsole2 m_Console; // A reference to the MMC console
- private IConsoleNameSpace2 m_ConsoleNameSpace; // A reference to the MMC console namespace
- private CNode[] m_NodeCollection; // The Nodes displayed in the snapin
-
- //-------------------------------------------------
- // CData - Constructor
- //
- // The constructor is responsible for constructing
- // the nodes that will be displayed in the snapin
- //-------------------------------------------------
- public CData()
- {
- // First, null out all the member variables
- m_Component = null;
- m_Console = null;
- m_ConsoleNameSpace = null;
-
- int i;
- NodeInfo[] Nodes;
-
- // Let's create the Node Structures
- Nodes = CreateNodes();
-
- int numNodes = Nodes.Length;
-
- m_NodeCollection = new CNode[numNodes];
-
- // Let's take this Node information structures and create Nodes with them
- for(i=0; i<numNodes; i++)
- m_NodeCollection[i] = new CNode(i, Nodes[i]);
-
- // Now add children nodes
- for(i=0; i<numNodes; i++)
- if (Nodes[i].iaChildren != null)
- for(int j=0; j<Nodes[i].iaChildren.Length; j++)
- m_NodeCollection[i].AddChild(ref m_NodeCollection[Nodes[i].iaChildren[j]]);
-
- // We should be ready to rock now!
-
- }// 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)
- {
- m_Console = (IConsole2)pUnknown;
- Marshal.AddRef(Marshal.GetIUnknownForObject(m_Console));
-
- m_ConsoleNameSpace = (IConsoleNameSpace2)pUnknown;
- Marshal.AddRef(Marshal.GetIUnknownForObject(m_ConsoleNameSpace));
-
- // Now we'll add the images we need for the snapin
- try
- {
- IImageList il=null;
- m_Console.QueryScopeImageList(out il);
-
- for(int i=0; i<m_NodeCollection.Length; i++)
- {
- il.ImageListSetIcon(m_NodeCollection[i].IconHandle, i);
- }
- }
- // For some reason, we tend to throw a 8004005 here (E_FAIL)... doesn't hurt us though
- catch(Exception)
- {
- }
- }// Initialize
-
- //-------------------------------------------------
- // CreateComponent
- //
- // This function creates the component object and
- // passes it back to the MMC
- //-------------------------------------------------
- public void CreateComponent(out IComponent ppComponent)
- {
- // Make sure we don't already have a component created
- if (m_Component == null)
- m_Component = new CComponent(ref m_NodeCollection);
-
- ppComponent = m_Component;
-
- }// CreateComponent
-
- //-------------------------------------------------
- // Notify
- //
- // This notify function is much less complex than
- // the notify function found in CComponent.
- // Its main responsiblity is to insert data items into
- // the console namespace when requested.
- //-------------------------------------------------
- public void Notify(IDataObject lpDataObject, uint aevent, int arg, int param)
- {
-
- CDO test= (CDO)lpDataObject;
-
- switch(aevent)
- {
- // If a data item is expanding, we need to tell MMC about it's children.
- // Note, this case doesn't necessarily mean the data item is expanding
- // visually.... MMC is just requesting information about it.
- case MMCN.EXPAND:
- // See if we're expanding the item (as opposed to collapsing it)
- if (arg > 0)
- test.Node.InsertChildren(ref m_ConsoleNameSpace, param);
- break;
-
- default:
- // We don't support any other messages
- throw new ExternalException("CData::Notify", HRESULT.S_FALSE);
- }
- }// Notify
-
- //-------------------------------------------------
- // Destroy
- //
- // This cleans up whatever needs to be cleaned up.
- // Normally, this would be used to release any interfaces
- // we had that traced back to the console. We can do this
- // by removing any references we have to the interfaces...
- //-------------------------------------------------
- public void Destroy()
- {
- Marshal.ReleaseComObject(m_Console);
- Marshal.ReleaseComObject(m_ConsoleNameSpace);
-
- m_Component = null;
- m_NodeCollection = null;
- }// Destroy
-
- //-------------------------------------------------
- // QueryDataObject
- //
- // When MMC wants a data object for a specific cookie,
- // this function will be called.
- //-------------------------------------------------
- public void QueryDataObject(int cookie, uint type, out IDataObject ppDataObject)
- {
- ppDataObject = new CDO(ref m_NodeCollection[cookie]);
- }// QueryDataObject
-
- //-------------------------------------------------
- // GetDisplayInfo
- //
- // This function is called by MMC whenever it needs to
- // display a node in the scope pane.
- //-------------------------------------------------
- public void GetDisplayInfo(ref SCOPEDATAITEM sdi)
- {
- // First let's find this node we want info on....
- CNode NodeWeWant = m_NodeCollection[(int)sdi.lParam];
-
- // See if they want the display name
- if ((sdi.mask & SDI.STR) > 0)
- sdi.displayname = Marshal.StringToCoTaskMemUni(NodeWeWant.DisplayName);
-
- // The snapin was set up so the cookie is the same
- // value as the image index
- if ((sdi.mask & SDI.IMAGE) > 0)
- sdi.nImage = NodeWeWant.Cookie;
-
- // We're using the same image for the "open" image as
- // we are the "closed" image
- if ((sdi.mask & SDI.OPENIMAGE) > 0)
- sdi.nOpenImage = NodeWeWant.Cookie;
-
- // We shouldn't need to set this.... but if we need to...
- if ((sdi.mask & SDI.STATE) > 0)
- sdi.nState = 0;
-
- // If we're inquiring about children....
- if ((sdi.mask & SDI.CHILDREN) > 0)
- sdi.cChildren = NodeWeWant.NumChildren;
-
- }// GetDisplayInfo
-
-
- //-------------------------------------------------
- // CompareObjects
- //
- // This function will compare two data objects. In this
- // snapin, if the cookies are identical for each data object,
- // then the items are the same
- //-------------------------------------------------
- public void CompareObjects(IDataObject lpDataObjectA, IDataObject lpDataObjectB)
- {
- CDO doItem1, doItem2;
- // These data items should be CDO's in disguise.....
- doItem1 = (CDO)lpDataObjectA;
- doItem2 = (CDO)lpDataObjectB;
-
- if (doItem1.Node.Cookie != doItem2.Node.Cookie)
- {
- // These are different objects. We need to return S_FALSE
-
- throw new ExternalException("CData::CompareObjects", HRESULT.S_FALSE);
- }
-
- // else we return S_OK automatically
- }// CompareObjects
-
- //----------------------------------------------------------
- // Functions to implement ISnapinHelp2
- //----------------------------------------------------------
-
- //-------------------------------------------------
- // GetHelpTopic
- //
- // This function passes back the location and filename
- // of a compiled help file
- //-------------------------------------------------
- public void GetHelpTopic(out int lpCompiledHelpFile)
- {
- // If this snapin doesn't have a helpfile, we need to
- // return false
- if (ThisSnapin.sHelpFile.Equals(""))
- {
- ExternalException e = new ExternalException("CData::GetHelpTopic", HRESULT.S_FALSE);
- throw e;
- }
-
- // We do have a help file. Let's pass it back.
- lpCompiledHelpFile = Marshal.StringToCoTaskMemUni(ThisSnapin.sHelpFile);
- }// GetHelpTopic
-
- //-------------------------------------------------
- // GetLinkedTopics
- //
- // We'd use this function if we had topics that were
- // not located in our primary help file.
- //-------------------------------------------------
- public void GetLinkedTopics(out int lpCompiledHelpFiles)
- {
- // We don't link to other Help files, so we throw false
- throw new ExternalException("CData::GetLinkedTopics", HRESULT.S_FALSE);
- }// GetLinkedTopics
-
- //-------------------------------------------------------
- // Stuff for IExtendPropertySheet
- //-------------------------------------------------------
-
- //-------------------------------------------------
- // CreatePropertyPages
- //
- // MMC calls this function when it wants a property
- // page for a specified node.
- //-------------------------------------------------
- public void CreatePropertyPages(IPropertySheetCallback lpProvider, int handle, IDataObject lpIDataObject)
- {
-
- // This is really a CDO in disguise
- CDO victim = (CDO)lpIDataObject;
-
- // Let's see if this node has property pages
- if (victim.Node.HavePropertyPages)
- victim.Node.CreatePropertyPages(lpProvider, handle);
-
- // We don't have any property pages, let's return false
- else
- throw new ExternalException("CData::CreatePropertyPages", HRESULT.S_FALSE);
-
- }// CreatePropertyPages
-
- //-------------------------------------------------
- // QueryPagesFor
- //
- // MMC calls this function once at the beginning when
- // everything is being initialized, asking if we have any
- // property pages. If we tell it we don't, we can never
- // have any property pages in our snapin. (It will never
- // call CreatePropertyPages)
- //-------------------------------------------------
- public void QueryPagesFor(IDataObject lpDataObject)
- {
-
- // This snapin does have property pages, so we should return S_OK
- // (which will happen automatically). If the snapin didn't have
- // any property pages, then we should return S_FALSE
- //
- // throw new ExternalException("", HRESULT.S_FALSE);
- //
- }// QueryPagesFor
-
- //-------------------------------------------------------
- // Functions that are not a part of any interface
- //-------------------------------------------------------
-
-
- //-------------------------------------------------
- // CreateNodes
- //
- // This ugly function creates the node info structs
- // that are used to create nodes for this snapin
- //-------------------------------------------------
- private NodeInfo[] CreateNodes()
- {
- NodeInfo[] nodes = new NodeInfo[11];
-
- CData cData = this;
-
- // Set up root node
- nodes[0] = new NodeInfo();
- nodes[0].sGuid = "123456789012345";
- nodes[0].sName = "Team Sites";
- nodes[0].sHelpLink = null;
- nodes[0].oResults = null;
- nodes[0].sIcon = "IDI_MAIN";
- nodes[0].ppaPages = null;
- nodes[0].iaChildren = new int[] {1,2};
-
- // Set up the North
- nodes[1] = new NodeInfo();
- nodes[1].sGuid = "123456789012345";
- nodes[1].sName = "North";
- nodes[1].sHelpLink = "snapsamp.chm::/step_one.htm";
- nodes[1].oResults = null;
- nodes[1].sIcon = "IDI_WHITE";
- nodes[1].ppaPages = null;
- nodes[1].iaChildren = new int[] {3,4,5,6};
-
- // Set up the South
- nodes[2] = new NodeInfo();
- nodes[2].sGuid = "123456789012345";
- nodes[2].sName = "South";
- nodes[2].sHelpLink = "snapsamp.chm::/step_two.htm";
- nodes[2].oResults = (Object)(new CDivisionResults());
- nodes[2].sIcon = "IDI_WHITE";
- nodes[2].ppaPages = null;
- nodes[2].iaChildren = null;
-
- // Set up the Blacks
- nodes[3] = new NodeInfo();
- nodes[3].sGuid = "123456789012345";
- nodes[3].sName = "Black";
- nodes[3].sHelpLink = null;
- nodes[3].oResults = new String[] {ThisSnapin.sBaseDir + "black1.html", ThisSnapin.sBaseDir + "black2.html"};
- nodes[3].sIcon = "IDI_BLACK";
- nodes[3].ppaPages = new IPropSheetPage[1] {new CTeamPropPage()};
- nodes[3].iaChildren = null;
-
- // Set up the Blues
- nodes[4] = new NodeInfo();
- nodes[4].sGuid = "123456789012345";
- nodes[4].sName = "Blue";
- nodes[4].sHelpLink = null;
- nodes[4].oResults = new String[] {ThisSnapin.sBaseDir + "blue1.html", ThisSnapin.sBaseDir + "blue2.html"};
- nodes[4].sIcon = "IDI_BLUE";
- nodes[4].ppaPages = new IPropSheetPage[1] {new CTeamPropPage()};
- nodes[4].iaChildren = null;
-
- // Set up the Cyans
- nodes[5] = new NodeInfo();
- nodes[5].sGuid = "123456789012345";
- nodes[5].sName = "Cyan";
- nodes[5].sHelpLink = null;
- nodes[5].oResults = new String[] {ThisSnapin.sBaseDir + "cyan1.html", ThisSnapin.sBaseDir + "cyan2.html"};
- nodes[5].sIcon = "IDI_CYAN";
- nodes[5].ppaPages = new IPropSheetPage[1] {new CTeamPropPage()};
- nodes[5].iaChildren = null;
-
- // Set up the Greens
- nodes[6] = new NodeInfo();
- nodes[6].sGuid = "123456789012345";
- nodes[6].sName = "Green";
- nodes[6].sHelpLink = null;
- nodes[6].oResults = new String[] {ThisSnapin.sBaseDir + "green1.html", ThisSnapin.sBaseDir + "green2.html"};
- nodes[6].sIcon = "IDI_GREEN";
- nodes[6].ppaPages = new IPropSheetPage[1] {new CTeamPropPage()};
- nodes[6].iaChildren = null;
-
- return nodes;
-
-
- }// CreateNodes
-
- }// class CData
-
- }// namespace Microsoft.SampleMMC
-