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