//------------------------------------------------------------------------------
/// <copyright from='2004' to='2005' company='Christian Forsberg'>
///		Copyright (c) Christian Forsberg, chris@businessanyplace.net.
///
///   This program is distributed in the hope that it will be useful,
///   but WITHOUT ANY WARRANTY; without even the implied warranty of
///   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
/// </copyright>
//------------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;

namespace TaskManager
{
	/// <summary>
	/// This is the process detail form.
	/// </summary>
  public class ProcessForm : System.Windows.Forms.Form
  {
    private Form parentForm;
    private string processName;
    private IntPtr processId;
    private int threadCount;
    private int baseAddress;

    #region Windows Form Designer declarations

    private System.Windows.Forms.MainMenu mainMenu;
    private System.Windows.Forms.Label processIdLabelLabel;
    private System.Windows.Forms.Label processIdLabel;
    private System.Windows.Forms.Label threadCountLabelLabel;
    private System.Windows.Forms.Label threadCountLabel;
    private System.Windows.Forms.Label baseAddressLabelLabel;
    private System.Windows.Forms.Label baseAddressLabel;
    private System.Windows.Forms.Label processNameLabel;
    private System.Windows.Forms.Label processNameLabelLabel;
    private System.Windows.Forms.MenuItem doneMenuItem;
    #endregion

    public ProcessForm(Form parentForm, string processName, IntPtr processId, int threadCount, int baseAddress)
    {
      this.processName = processName;
      this.parentForm = parentForm;
      this.processId = processId;
      this.threadCount = threadCount;
      this.baseAddress = baseAddress;

      InitializeComponent();
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.mainMenu = new System.Windows.Forms.MainMenu();
      this.doneMenuItem = new System.Windows.Forms.MenuItem();
      this.processIdLabelLabel = new System.Windows.Forms.Label();
      this.processIdLabel = new System.Windows.Forms.Label();
      this.threadCountLabelLabel = new System.Windows.Forms.Label();
      this.threadCountLabel = new System.Windows.Forms.Label();
      this.baseAddressLabelLabel = new System.Windows.Forms.Label();
      this.baseAddressLabel = new System.Windows.Forms.Label();
      this.processNameLabel = new System.Windows.Forms.Label();
      this.processNameLabelLabel = new System.Windows.Forms.Label();
      // 
      // mainMenu
      // 
      this.mainMenu.MenuItems.Add(this.doneMenuItem);
      // 
      // doneMenuItem
      // 
      this.doneMenuItem.Text = "Done";
      this.doneMenuItem.Click += new System.EventHandler(this.doneMenuItem_Click);
      // 
      // processIdLabelLabel
      // 
      this.processIdLabelLabel.Location = new System.Drawing.Point(4, 46);
      this.processIdLabelLabel.Size = new System.Drawing.Size(168, 22);
      this.processIdLabelLabel.Text = "Process ID:";
      // 
      // processIdLabel
      // 
      this.processIdLabel.Font = new System.Drawing.Font("Nina", 11F, System.Drawing.FontStyle.Regular);
      this.processIdLabel.Location = new System.Drawing.Point(4, 68);
      this.processIdLabel.Size = new System.Drawing.Size(168, 22);
      this.processIdLabel.Text = "<ProcessID>";
      // 
      // threadCountLabelLabel
      // 
      this.threadCountLabelLabel.Location = new System.Drawing.Point(4, 90);
      this.threadCountLabelLabel.Size = new System.Drawing.Size(168, 22);
      this.threadCountLabelLabel.Text = "Thread Count:";
      // 
      // threadCountLabel
      // 
      this.threadCountLabel.Font = new System.Drawing.Font("Nina", 11F, System.Drawing.FontStyle.Regular);
      this.threadCountLabel.Location = new System.Drawing.Point(4, 112);
      this.threadCountLabel.Size = new System.Drawing.Size(168, 22);
      this.threadCountLabel.Text = "<ThreadCount>";
      // 
      // baseAddressLabelLabel
      // 
      this.baseAddressLabelLabel.Location = new System.Drawing.Point(4, 134);
      this.baseAddressLabelLabel.Size = new System.Drawing.Size(168, 22);
      this.baseAddressLabelLabel.Text = "Base Address:";
      // 
      // baseAddressLabel
      // 
      this.baseAddressLabel.Font = new System.Drawing.Font("Nina", 11F, System.Drawing.FontStyle.Regular);
      this.baseAddressLabel.Location = new System.Drawing.Point(4, 156);
      this.baseAddressLabel.Size = new System.Drawing.Size(168, 22);
      this.baseAddressLabel.Text = "<BaseAddress>";
      // 
      // processNameLabel
      // 
      this.processNameLabel.Font = new System.Drawing.Font("Nina", 11F, System.Drawing.FontStyle.Regular);
      this.processNameLabel.Location = new System.Drawing.Point(4, 24);
      this.processNameLabel.Size = new System.Drawing.Size(168, 22);
      this.processNameLabel.Text = "<ProcessName>";
      // 
      // processNameLabelLabel
      // 
      this.processNameLabelLabel.Font = new System.Drawing.Font("Nina", 11F, System.Drawing.FontStyle.Bold);
      this.processNameLabelLabel.Location = new System.Drawing.Point(4, 2);
      this.processNameLabelLabel.Size = new System.Drawing.Size(168, 22);
      this.processNameLabelLabel.Text = "Name:";
      // 
      // ProcessForm
      // 
      this.ClientSize = new System.Drawing.Size(178, 184);
      this.Controls.Add(this.processNameLabel);
      this.Controls.Add(this.processNameLabelLabel);
      this.Controls.Add(this.baseAddressLabel);
      this.Controls.Add(this.baseAddressLabelLabel);
      this.Controls.Add(this.threadCountLabel);
      this.Controls.Add(this.threadCountLabelLabel);
      this.Controls.Add(this.processIdLabel);
      this.Controls.Add(this.processIdLabelLabel);
      this.Menu = this.mainMenu;
      this.Text = "Process";
      this.Closing += new System.ComponentModel.CancelEventHandler(this.ProcessForm_Closing);
      this.Load += new System.EventHandler(this.ProcessForm_Load);

    }
    #endregion

    private void ProcessForm_Load(object sender, System.EventArgs e)
    {
      processNameLabel.Text = processName;
      processIdLabel.Text = string.Format("{0:X}", (int)processId);
      threadCountLabel.Text = threadCount.ToString();
      baseAddressLabel.Text = string.Format("{0:X}", baseAddress);

      this.parentForm.Hide();
      Cursor.Current = Cursors.Default;
    }

    private void doneMenuItem_Click(object sender, System.EventArgs e)
    {
      this.Close();
    }

    private void ProcessForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
      parentForm.Show();
    }

    #region IDisposable members
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Dispose( bool disposing )
    {
      base.Dispose( disposing );
    }
    #endregion
  }
}
