home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------------------------------
- // CTeamPropPage.cs
- //
- // This implements the application-specific interface IPropSheetPage
- // to create a property page that is used by each team in the snapin.
- //
- // The page allows the user to determine which HTML pages to display
- // in the result pane for each team.
- //
- // This property page uses WFC extensively.
- //-------------------------------------------------------------
-
- using System;
- using System.Runtime.InteropServices;
- using System.Drawing;
- using System.WinForms;
-
- namespace Microsoft.SampleMMC
- {
- public class CTeamPropPage : IPropSheetPage
- {
- int m_hWnd; // The window handle for the page
- CNode m_Node; // The node this property page represents
- int m_iDefault; // The "default page" MMC will display
- String[] m_saResults; // Our local copy of links
-
- // The list of controls on this page
- ListBox m_lbList; // The listbox that holds possible links
- TextBox m_txtCur; // The textbox that holds "working" link
- Button m_btnAdd; // The "Add" button
- Button m_btnDelete; // The "Delete" button
- Button m_btnSet; // The "Set" button (Sets the default link)
- Label m_label1; // The label describing the page
-
- //-------------------------------------------------
- // Init
- //
- // This function is in place in order to set up
- // the page. Primarily, it is here so the Property
- // page can get a reference to the Node it represents,
- // so it may modify its values
- //-------------------------------------------------
- public void Init(ref Object info)
- {
- m_Node = (CNode)info;
- m_iDefault = m_Node.ResultNum;
-
- // Now copy over the node's links and store them locally (for editing)
- if (m_Node.m_oResults != null)
- {
- int iNum = ((String[])(m_Node.m_oResults)).Length;
- m_saResults = new String[iNum];
- for(int i=0; i<iNum; i++)
- m_saResults[i] = ((String[])(m_Node.m_oResults))[i];
- }
- else
- m_saResults=null;
- }// Init
-
- //-------------------------------------------------
- // Title
- //
- // Returns the title of the property page (the same
- // title as the node it represents)
- //-------------------------------------------------
- public String Title()
- {
- return m_Node.DisplayName;
- }// Title
-
- //-------------------------------------------------
- // Icon
- //
- // Returns a handle to the icon representing the
- // property page (the same as the node it represents)
- //-------------------------------------------------
- public int Icon()
- {
- return m_Node.IconHandle;
- }// Icon
-
- //-------------------------------------------------
- // InsertPropSheetPageControls
- //
- // This function creates all the controls for the
- // property sheet and places them on the form
- //-------------------------------------------------
- public int InsertPropSheetPageControls(int hWnd)
- {
- m_lbList = new ListBox();
- m_txtCur = new TextBox();
- m_btnAdd = new Button();
- m_btnDelete = new Button();
- m_btnSet = new Button();
- m_label1 = new Label();
-
-
- m_hWnd = hWnd;
-
- // Set up the Listbox first
-
- // We need to set the listbox's parent window to the
- // window handle that was passed into the function
- SetParent(m_lbList.Handle, m_hWnd);
- m_lbList.Location = new Point(40, 136);
- m_lbList.Size = new Size(208, 95);
- m_lbList.TabIndex = 0;
- m_lbList.Text = "Listed Sites";
- m_lbList.UseTabStops = true;
- // Add an event handler
- m_lbList.AddOnClick(new EventHandler(onlbListClick));
- InsertStrings();
-
- // Now set up the edit box
- SetParent(m_txtCur.Handle, m_hWnd);
- m_txtCur.Location = new Point(40, 48);
- m_txtCur.Size = new Size(208, 20);
- m_txtCur.TabIndex = 1;
- m_txtCur.Text = "";
-
- // Now the add button
- SetParent(m_btnAdd.Handle, m_hWnd);
- m_btnAdd.Location = new Point(40, 88);
- m_btnAdd.Size = new Size(64, 24);
- m_btnAdd.TabIndex = 2;
- m_btnAdd.Text = "Add";
- // Adding an event handler here...
- m_btnAdd.AddOnClick(new EventHandler(onbtnAddClick));
-
-
- // Add the set button
- SetParent(m_btnSet.Handle, m_hWnd);
- m_btnSet.Location = new Point(110, 88);
- m_btnSet.Size = new Size(64, 24);
- m_btnSet.TabIndex = 3;
- m_btnSet.Text = "Set";
- // Event handler...
- m_btnSet.AddOnClick(new EventHandler(onbtnSetClick));
-
- // Add the delete button
- SetParent(m_btnDelete.Handle, m_hWnd);
- m_btnDelete.Location = new Point(184, 88);
- m_btnDelete.Size = new Size(64, 24);
- m_btnDelete.TabIndex = 4;
- m_btnDelete.Text = "Delete";
- // Event handler....
- m_btnDelete.AddOnClick(new EventHandler(onbtnDeleteClick));
-
-
- // Add the label for the page
- SetParent(m_label1.Handle, m_hWnd);
- m_label1.Location = new Point(48, 8);
- m_label1.Size = new Size(192, 24);
- m_label1.TabStop = false;
- m_label1.Text = "Selected Page to Visit";
-
- return 1;
-
- }// InsertPropSheetPageControls
-
- //-------------------------------------------------
- // InsertStrings
- //
- // This function will add all the possibilities for
- // links into the listbox
- //-------------------------------------------------
- private void InsertStrings()
- {
- String sToAdd;
-
- // In case there's stuff already in the listbox, let's
- // clear it out
- m_lbList.Items.Clear();
-
- // Check to make sure we have result data to display
- if (m_saResults != null)
- {
- int iLength = m_saResults.Length;
-
- // We run through the list backwards, so we can insert everything
- // at the front of the list and it comes out in the correct order
- for(int i=iLength-1; i>=0; i--)
- {
- sToAdd = m_saResults[i];
-
- // Just to be cool, we'll put a * in front of the default link
- if (m_iDefault == i)
- sToAdd = "* " + sToAdd;
-
- // And now insert the item into the list
- m_lbList.InsertItem(0,sToAdd);
- }
- }
- }// InsertStrings
-
- //-------------------------------------------------
- // onbtnSetClick
- //
- // Event handler for the clicking of the set button
- //-------------------------------------------------
- void onbtnSetClick(Object o, EventArgs e)
- {
- // Make sure they have a valid item selected
- if (m_lbList.SelectedIndex != -1)
- {
- m_iDefault = m_lbList.SelectedIndex;
-
- // Let's reinsert all the strings into the listbox
- // so we can get the * infront of our newly selected item
- InsertStrings();
- // Now turn on the apply button
- ActivateApply();
- }
- }// onbtnSetClick
-
- //-------------------------------------------------
- // onlbListClick
- //
- // Event handler for the clicking of an item in the
- // listbox
- //-------------------------------------------------
- void onlbListClick(Object o, EventArgs e)
- {
- // We'll put the currently selected item in
- // the "working" box
- if (m_lbList.SelectedIndex >=0)
- m_txtCur.Text = m_saResults[m_lbList.SelectedIndex];
- }// onlbListClick
-
- //-------------------------------------------------
- // onbtnDeleteClick
- //
- // Event handler for the clicking of the delete button
- //-------------------------------------------------
- void onbtnDeleteClick(Object o, EventArgs e)
- {
- // Make sure they have a valid item selected
- if (m_lbList.SelectedIndex != -1)
- {
- // If that was the default link, we need to make a new
- // link the default
- if (m_lbList.SelectedIndex == m_iDefault && m_iDefault>0)
- m_iDefault--;
-
- // Let's remove this item from our local Result Array
- String[] tempResult = new String[m_saResults.Length-1];
- int i=0, j=0;
- for(i=0;i< m_saResults.Length; i++)
- {
- if (i != m_lbList.SelectedIndex)
- tempResult[j++] = m_saResults[i];
- }
-
- m_saResults = tempResult;
-
- // Reinsert all the strings
- InsertStrings();
- // Activate the Apply button
- ActivateApply();
- }
- }// onbtnDeleteClick
-
- //-------------------------------------------------
- // onbtnAddClick
- //
- // Event handler for the clicking of the add button
- //-------------------------------------------------
- void onbtnAddClick(Object o, EventArgs e)
- {
- // Make sure we're not trying to add nothing
- if (!m_txtCur.Text.Equals(""))
- {
-
- // Let's add the selected item into our local Result array
- String[] tempResult = new String[m_saResults.Length+1];
- int i;
- for(i=0; i<m_saResults.Length; i++)
- tempResult[i] = m_saResults[i];
-
- // Now add the new guy
- tempResult[i] = m_txtCur.Text;
-
- m_saResults = tempResult;
-
- // Now clear out the text field.
- m_txtCur.Text = "";
-
- // Now re-add everything to the listbox
- InsertStrings();
- // Turn on the apply button
- ActivateApply();
- }
- }// onbtnAddClick
-
- //-------------------------------------------------
- // ApplyData
- //
- // This function will write all the Property page
- // information to the node it represents
- //-------------------------------------------------
- public int ApplyData()
- {
- m_Node.m_oResults = m_saResults;
- m_Node.ResultNum = m_iDefault;
-
- return 1;
- }// ApplyData
-
- //-------------------------------------------------
- // ActivateApply
- //
- // This function will turn on the apply button by sending
- // a message to the parent window
- //-------------------------------------------------
- private void ActivateApply()
- {
- SendMessage(GetParent(m_hWnd), PSM.CHANGED, (uint)m_hWnd, 0);
- }// ActivateApply
-
- //-------------------------------------------------
- // We need to import the Win32 API calls used to deal with
- // window messaging.
- //-------------------------------------------------
- [DllImport("user32.dll")]
- public static extern int SendMessage(int hWnd, uint Msg, uint wParam, uint lParam);
- [DllImport("user32.dll")]
- public static extern int SetParent(int hWndChild, int hWndNewParent);
- [DllImport("user32.dll")]
- public static extern int GetParent(int hWnd);
- }// class CTeamPropPage
- }// namespace Microsoft.SampleMMC
-
-