Form1.cs
author sl
Thu, 18 Dec 2014 22:43:32 +0100
changeset 31 958ed29f977c
parent 30 8ce9bdc9c5b5
child 36 259e823a8e84
permissions -rw-r--r--
Minor usage table renaming.
     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 bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
   126 		{
   127             bool processed = false;
   128 			_timer.Enabled = false;
   129             if (e.Button != RemoteControlButton.Unknown)
   130             {
   131                 label1.Text = e.Button.ToString();
   132                 processed = true;
   133             }
   134             else if (e.MceButton != Hid.UsageTables.WindowsMediaCenterRemoteControl.Null)
   135             {
   136                 //Display MCE button name
   137                 label1.Text = e.MceButton.ToString();
   138                 //Check if this is an HP extension
   139                 if (Enum.IsDefined(typeof(Hid.UsageTables.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton))
   140                 {
   141                     //Also display HP button name
   142                     label1.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)e.MceButton).ToString();
   143                 }
   144 
   145                 processed = true;
   146             }
   147             else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null)
   148             {
   149                 //Display consumer control name
   150                 label1.Text = e.ConsumerControl.ToString();
   151                 processed = true;
   152             }
   153             else
   154             {
   155                 label1.Text = "Unknown";
   156             }
   157 			label2.Text = e.Device.ToString();
   158 			_timer.Enabled = true;
   159             return processed;
   160 		}
   161 
   162 		private void _timer_Tick(object sender, EventArgs e)
   163 		{
   164 			_timer.Enabled = false;
   165 			label1.Text = "Ready...";
   166 		}
   167 	}
   168 }