home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 40 / IOPROG_40.ISO / SOFT / NETFrameworkSDK.exe / comsdk.cab / samples.exe / mmc / CDivisionResults.cs < prev    next >
Encoding:
Text File  |  2000-06-23  |  5.8 KB  |  176 lines

  1. //-------------------------------------------------------------
  2. // CDivision.cs
  3. //
  4. // This implements the application-specific interface IColumnResultView 
  5. // and provides the methods to display a custom list view in the result 
  6. // pane of a specific division
  7. //-------------------------------------------------------------
  8. using System;
  9. using System.Runtime.InteropServices;
  10.  
  11. namespace Microsoft.SampleMMC
  12. {
  13.  
  14. public class CDivisionResults : IColumnResultView
  15. {
  16.     private String[]    m_saColumnNames;    // The column headers
  17.     private String[,]   m_saaValues;        // The values in the table
  18.     private int[]       m_haIcons;          // The icons this listview uses
  19.     private int         m_iImageIndexBase;  // Used to determine the base for image indicies
  20.  
  21.     
  22.     //-------------------------------------------------
  23.     // getNumColumns
  24.     //
  25.     // This function returns the number of Columns in
  26.     // the table
  27.     //-------------------------------------------------
  28.     public int getNumColumns()
  29.     {
  30.         return m_saColumnNames.Length;
  31.     }// getNumColumns
  32.  
  33.     //-------------------------------------------------
  34.     // getNumRows
  35.     //
  36.     // This function returns the number of rows (not counting
  37.     // the "header" row) in the table
  38.     //-------------------------------------------------
  39.     public int getNumRows()
  40.     {
  41.         // Hard coded, since the rest of the table is hard
  42.         // coded as well.
  43.         return 3;
  44.     }// getNumRows
  45.  
  46.     //-------------------------------------------------
  47.     // getColumnsTitles
  48.     //
  49.     // This function returns the specified column title
  50.     // for this table
  51.     //-------------------------------------------------
  52.     public String getColumnTitles(int iIndex)
  53.     {
  54.         // Make sure the index they passed in is valid
  55.         if (iIndex >= 0 && iIndex< getNumColumns())
  56.             return m_saColumnNames[iIndex];
  57.         else
  58.             throw new Exception("Index out of bounds");
  59.     }// getColumnTitles
  60.  
  61.     //-------------------------------------------------
  62.     // getValues
  63.     //
  64.     // Given x and y values, this function returns the 
  65.     // corresponding "cell" in the table.
  66.     //-------------------------------------------------
  67.     public String getValues(int iX, int iY)
  68.     {
  69.         // Make sure the indicies they give us are valid
  70.         if (iX >=0 && iX<getNumRows() && iY>=0 && iY<getNumColumns())
  71.             return m_saaValues[iX,iY];
  72.         else
  73.             throw new Exception("Index out of bounds!");
  74.     }// getValues
  75.  
  76.     //-------------------------------------------------
  77.     // AddImages
  78.     //
  79.     // This adds the listview's icons to the image list
  80.     //-------------------------------------------------
  81.     public void AddImages(ref IImageList il)
  82.     {
  83.         for(int i=0; i<m_haIcons.Length; i++)
  84.             il.ImageListSetIcon(m_haIcons[i], m_iImageIndexBase+i);
  85.  
  86.     }// AddImages
  87.  
  88.     //-------------------------------------------------
  89.     // GetImageIndex
  90.     //
  91.     // This function returns the image index that was used for 
  92.     // a given item's icon
  93.     //-------------------------------------------------
  94.     public int GetImageIndex(int i)
  95.     {
  96.         return m_iImageIndexBase+i;
  97.     }// GetImageIndex
  98.     
  99.     //-------------------------------------------------
  100.     // CDivisionResults - Constructor
  101.     //
  102.     // The constructor sets up the arrays m_saColumnNames and
  103.     // m_saaValues with the data that will be displayed on 
  104.     // the screen
  105.     //-------------------------------------------------
  106.     public CDivisionResults()
  107.     {
  108.         int hModule = Marshal.GetHINSTANCE(this.GetType().Module); 
  109.  
  110.         // We have 3 images
  111.         m_haIcons = new int[3];
  112.         
  113.         // First set up the Column headers
  114.         // There are spaces in the column names to make the cells
  115.         // longer, so city and team names will fit in the cell
  116.         // (Cell sizes are determined by the length of the column name
  117.  
  118.         m_saColumnNames = new String[3];
  119.         m_saColumnNames[0] = "   Home City   ";
  120.         m_saColumnNames[1] = "   Team Name  ";
  121.         m_saColumnNames[2] = "  The Big Star  ";
  122.  
  123.         // Now we'll just put in the data to fill the table
  124.         m_saaValues = new String[3,3];
  125.  
  126.         m_saaValues[0,0] = "Sioux Falls";
  127.         m_saaValues[0,1] = "Purples";
  128.         m_saaValues[0,2] = "Big Man";
  129.  
  130.         // Load this items's icon
  131.         m_haIcons[0] = LoadIcon(hModule, "IDI_PURPLE");
  132.  
  133.         m_saaValues[1,0] = "Oklahoma City";
  134.         m_saaValues[1,1] = "Yellows";
  135.         m_saaValues[1,2] = "Sandman";
  136.  
  137.         // Load this items's icon
  138.         m_haIcons[1] = LoadIcon(hModule, "IDI_YELLOW");
  139.  
  140.         m_saaValues[2,0] = "Santa Fe";
  141.         m_saaValues[2,1] = "Reds";
  142.         m_saaValues[2,2] = "Bashful";
  143.  
  144.         // Load this items's icon
  145.         m_haIcons[2] = LoadIcon(hModule, "IDI_RED");
  146.  
  147.         // This is a safe number to use (for this snapin)
  148.         m_iImageIndexBase=100;
  149.  
  150.  
  151.     }// CDivisionResults
  152.  
  153.     //-------------------------------------------------
  154.     // ~CDivisionResults - Destructor
  155.     //
  156.     // The destructor frees all the handles to the icons
  157.     //-------------------------------------------------
  158.     ~CDivisionResults()
  159.     {
  160.         for(int i=0; i<m_haIcons.Length; i++)
  161.             DestroyIcon(m_haIcons[i]);
  162.     }// ~CDivisonResults
  163.  
  164.     
  165.     //-------------------------------------------------
  166.     // We need to import the Win32 API calls used to deal with
  167.     // image loading.
  168.     //-------------------------------------------------
  169.     [DllImport("user32.dll")]
  170.     public static extern int LoadIcon(int hinst, String name);
  171.     [DllImport("user32.dll")]
  172.     public static extern int DestroyIcon(int hIcon);
  173.  
  174. }// class CDivisionResults
  175. }// namespace Microsoft.SampleMMC
  176.