Form1.cs
author sl
Wed, 03 Dec 2014 21:54:45 +0100
changeset 16 9a3e77655031
parent 9 94850bfc12b5
child 19 d066e3999973
permissions -rw-r--r--
Now supporting alternative codes for program guid and properties/info.
     1 using System;
     2 using System.Drawing;
     3 using System.Collections;
     4 using System.ComponentModel;
     5 using System.Windows.Forms;
     6 using System.Data;
     7 using Devices.RemoteControl;
     8 
     9 namespace RemoteControlSample
    10 {
    11 	/// <summary>
    12 	/// Summary description for Form1.
    13 	/// </summary>
    14 	public class Form1 : System.Windows.Forms.Form
    15 	{
    16 		/// <summary>
    17 		/// Required designer variable.
    18 		/// </summary>
    19 		private System.ComponentModel.Container components = null;
    20 		private System.Windows.Forms.Label label1;
    21 		private RemoteControlDevice _remote;
    22 		private System.Windows.Forms.Label label2;
    23 		private Timer _timer;
    24 
    25 		public Form1()
    26 		{
    27 			//
    28 			// Required for Windows Form Designer support
    29 			//
    30 			InitializeComponent();
    31 
    32 			_timer = new Timer();
    33 			_timer.Interval = 3000;
    34 			_timer.Enabled = false;
    35 			_timer.Tick +=new EventHandler(_timer_Tick);            
    36 		}
    37 
    38 		/// <summary>
    39 		/// Clean up any resources being used.
    40 		/// </summary>
    41 		protected override void Dispose( bool disposing )
    42 		{
    43 			if( disposing )
    44 			{
    45 				if (components != null)
    46 				{
    47 					components.Dispose();
    48 				}
    49 			}
    50 			base.Dispose( disposing );
    51 		}
    52 
    53 		#region Windows Form Designer generated code
    54 		/// <summary>
    55 		/// Required method for Designer support - do not modify
    56 		/// the contents of this method with the code editor.
    57 		/// </summary>
    58 		private void InitializeComponent()
    59 		{
    60 			this.label1 = new System.Windows.Forms.Label();
    61 			this.label2 = new System.Windows.Forms.Label();
    62 			this.SuspendLayout();
    63 			//
    64 			// label1
    65 			//
    66 			this.label1.Dock = System.Windows.Forms.DockStyle.Fill;
    67 			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 36F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    68 			this.label1.ForeColor = System.Drawing.Color.White;
    69 			this.label1.Location = new System.Drawing.Point(0, 0);
    70 			this.label1.Name = "label1";
    71 			this.label1.Size = new System.Drawing.Size(736, 266);
    72 			this.label1.TabIndex = 0;
    73 			this.label1.Text = "Ready...";
    74 			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    75 			//
    76 			// label2
    77 			//
    78 			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 16F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    79 			this.label2.Location = new System.Drawing.Point(72, 32);
    80 			this.label2.Name = "label2";
    81 			this.label2.Size = new System.Drawing.Size(576, 23);
    82 			this.label2.TabIndex = 1;
    83 			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
    84 			//
    85 			// Form1
    86 			//
    87 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    88 			this.BackColor = System.Drawing.Color.LightSteelBlue;
    89 			this.ClientSize = new System.Drawing.Size(736, 266);
    90 			this.Controls.Add(this.label2);
    91 			this.Controls.Add(this.label1);
    92 			this.Name = "Form1";
    93 			this.Text = "Remote Control Sample";
    94 			this.Load += new System.EventHandler(this.Form1_Load);
    95 			this.ResumeLayout(false);
    96 
    97 		}
    98 		#endregion Windows Form Designer generated code
    99 
   100 		/// <summary>
   101 		/// The main entry point for the application.
   102 		/// </summary>
   103 		[STAThread]
   104 		static void Main()
   105 		{
   106 			Application.Run(new Form1());
   107 		}
   108 
   109 		private void Form1_Load(object sender, System.EventArgs e)
   110 		{
   111             _remote = new RemoteControlDevice(this.Handle);
   112             _remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed);
   113 		}
   114 
   115 
   116 		protected override void WndProc(ref Message message)
   117 		{
   118             if (_remote != null)
   119             {
   120                 _remote.ProcessMessage(message);
   121             }
   122 			base.WndProc(ref message);
   123 		}
   124 
   125 		private void _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
   126 		{
   127 			_timer.Enabled = false;
   128             if (e.Button != RemoteControlButton.Unknown)
   129             {
   130                 label1.Text = e.Button.ToString();
   131             }
   132             else if (e.MceButton != Hid.UsageTables.MceButton.Null)
   133             {
   134                 //Display MCE button name
   135                 label1.Text = e.MceButton.ToString();
   136                 //Check if this is an HP extension
   137                 if (Enum.IsDefined(typeof(Hid.UsageTables.HpMceButton), (ushort)e.MceButton))
   138                 {
   139                     //Also display HP button name
   140                     label1.Text += " / HP:" + ((Hid.UsageTables.HpMceButton)e.MceButton).ToString();
   141                 }
   142             }
   143             else
   144             {
   145                 label1.Text = "Unknown";
   146             }
   147 			label2.Text = e.Device.ToString();
   148 			_timer.Enabled = true;
   149 		}
   150 
   151 		private void _timer_Tick(object sender, EventArgs e)
   152 		{
   153 			_timer.Enabled = false;
   154 			label1.Text = "Ready...";
   155 		}
   156 	}
   157 }