Cast fix and moving Win32 stuff in a dedicated file.
3 using System.Collections;
4 using System.ComponentModel;
5 using System.Windows.Forms;
7 using Devices.RemoteControl;
9 namespace RemoteControlSample
12 /// Summary description for Form1.
14 public class Form1 : System.Windows.Forms.Form
17 /// Required designer variable.
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;
28 // Required for Windows Form Designer support
30 InitializeComponent();
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);
41 /// Clean up any resources being used.
43 protected override void Dispose( bool disposing )
47 if (components != null)
52 base.Dispose( disposing );
55 #region Windows Form Designer generated code
57 /// Required method for Designer support - do not modify
58 /// the contents of this method with the code editor.
60 private void InitializeComponent()
62 this.label1 = new System.Windows.Forms.Label();
63 this.label2 = new System.Windows.Forms.Label();
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;
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;
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);
95 this.Text = "Remote Control Sample";
96 this.Load += new System.EventHandler(this.Form1_Load);
97 this.ResumeLayout(false);
100 #endregion Windows Form Designer generated code
103 /// The main entry point for the application.
108 Application.Run(new Form1());
111 private void Form1_Load(object sender, System.EventArgs e)
117 protected override void WndProc(ref Message message)
119 _remote.ProcessMessage(message);
120 base.WndProc(ref message);
123 private void _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
125 _timer.Enabled = false;
126 if (e.Button != RemoteControlButton.Unknown)
128 label1.Text = e.Button.ToString();
130 else if (e.MceButton != Hid.UsageTables.MceButton.Null)
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))
137 //Also display HP button name
138 label1.Text += " / HP:" + ((Hid.UsageTables.HpMceButton)e.MceButton).ToString();
143 label1.Text = "Unknown";
145 label2.Text = e.Device.ToString();
146 _timer.Enabled = true;
149 private void _timer_Tick(object sender, EventArgs e)
151 _timer.Enabled = false;
152 label1.Text = "Ready...";