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