sl@0: using System;
sl@0: using System.Drawing;
sl@0: using System.Collections;
sl@0: using System.ComponentModel;
sl@0: using System.Windows.Forms;
sl@0: using System.Data;
sl@6: using Devices.RemoteControl;
sl@0:
sl@0: namespace RemoteControlSample
sl@0: {
sl@0: ///
sl@0: /// Summary description for Form1.
sl@0: ///
sl@36: public class MainForm : System.Windows.Forms.Form
sl@0: {
sl@0: ///
sl@0: /// Required designer variable.
sl@0: ///
sl@38: private System.ComponentModel.Container components = null;
sl@38: private RemoteControlDevice _remote;
sl@38: private Label labelButtonName;
sl@38: private Label labelDeviceName;
sl@39: private ListView listViewEvents;
StephaneLenclud@49: private ColumnHeader columnHeaderUsages;
sl@40: private ColumnHeader columnHeaderUsagePage;
sl@40: private ColumnHeader columnHeaderUsageCollection;
sl@42: private ColumnHeader columnHeaderRepeat;
sl@44: private ColumnHeader columnHeaderTime;
StephaneLenclud@49: private Button buttonClear;
StephaneLenclud@49: private ColumnHeader columnHeaderInputReport;
sl@0: private Timer _timer;
sl@0:
sl@41: public delegate void OnHidEventDelegate(object aSender, Hid.HidEvent aHidEvent);
sl@41:
sl@36: public MainForm()
sl@0: {
sl@0: //
sl@0: // Required for Windows Form Designer support
sl@0: //
sl@0: InitializeComponent();
sl@0:
sl@0: _timer = new Timer();
sl@0: _timer.Interval = 3000;
sl@0: _timer.Enabled = false;
sl@15: _timer.Tick +=new EventHandler(_timer_Tick);
sl@0: }
sl@0:
sl@0: ///
sl@0: /// Clean up any resources being used.
sl@0: ///
sl@0: protected override void Dispose( bool disposing )
sl@0: {
sl@0: if( disposing )
sl@0: {
sl@6: if (components != null)
sl@0: {
sl@0: components.Dispose();
sl@0: }
sl@0: }
sl@0: base.Dispose( disposing );
sl@0: }
sl@0:
sl@0: #region Windows Form Designer generated code
sl@0: ///
sl@0: /// Required method for Designer support - do not modify
sl@0: /// the contents of this method with the code editor.
sl@0: ///
sl@0: private void InitializeComponent()
sl@0: {
StephaneLenclud@49: this.labelButtonName = new System.Windows.Forms.Label();
StephaneLenclud@49: this.labelDeviceName = new System.Windows.Forms.Label();
StephaneLenclud@49: this.listViewEvents = new System.Windows.Forms.ListView();
StephaneLenclud@49: this.columnHeaderUsages = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
StephaneLenclud@49: this.columnHeaderUsagePage = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
StephaneLenclud@49: this.columnHeaderUsageCollection = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
StephaneLenclud@49: this.columnHeaderRepeat = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
StephaneLenclud@49: this.columnHeaderTime = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
StephaneLenclud@49: this.buttonClear = new System.Windows.Forms.Button();
StephaneLenclud@49: this.columnHeaderInputReport = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
StephaneLenclud@49: this.SuspendLayout();
StephaneLenclud@49: //
StephaneLenclud@49: // labelButtonName
StephaneLenclud@49: //
StephaneLenclud@49: this.labelButtonName.AutoSize = true;
StephaneLenclud@49: this.labelButtonName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
StephaneLenclud@49: this.labelButtonName.Location = new System.Drawing.Point(811, 55);
StephaneLenclud@49: this.labelButtonName.Name = "labelButtonName";
StephaneLenclud@49: this.labelButtonName.Size = new System.Drawing.Size(103, 20);
StephaneLenclud@49: this.labelButtonName.TabIndex = 0;
StephaneLenclud@49: this.labelButtonName.Text = "Button Name";
StephaneLenclud@49: //
StephaneLenclud@49: // labelDeviceName
StephaneLenclud@49: //
StephaneLenclud@49: this.labelDeviceName.AutoSize = true;
StephaneLenclud@49: this.labelDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
StephaneLenclud@49: this.labelDeviceName.Location = new System.Drawing.Point(811, 35);
StephaneLenclud@49: this.labelDeviceName.Name = "labelDeviceName";
StephaneLenclud@49: this.labelDeviceName.Size = new System.Drawing.Size(103, 20);
StephaneLenclud@49: this.labelDeviceName.TabIndex = 1;
StephaneLenclud@49: this.labelDeviceName.Text = "Device Name";
StephaneLenclud@49: //
StephaneLenclud@49: // listViewEvents
StephaneLenclud@49: //
StephaneLenclud@49: this.listViewEvents.Alignment = System.Windows.Forms.ListViewAlignment.Left;
StephaneLenclud@49: this.listViewEvents.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
sl@39: | System.Windows.Forms.AnchorStyles.Left)));
StephaneLenclud@49: this.listViewEvents.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
StephaneLenclud@49: this.listViewEvents.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
StephaneLenclud@49: this.columnHeaderUsages,
StephaneLenclud@49: this.columnHeaderInputReport,
sl@40: this.columnHeaderUsagePage,
sl@42: this.columnHeaderUsageCollection,
sl@44: this.columnHeaderRepeat,
sl@44: this.columnHeaderTime});
StephaneLenclud@49: this.listViewEvents.GridLines = true;
StephaneLenclud@49: this.listViewEvents.Location = new System.Drawing.Point(12, 12);
StephaneLenclud@49: this.listViewEvents.Name = "listViewEvents";
StephaneLenclud@49: this.listViewEvents.Size = new System.Drawing.Size(766, 369);
StephaneLenclud@49: this.listViewEvents.TabIndex = 2;
StephaneLenclud@49: this.listViewEvents.UseCompatibleStateImageBehavior = false;
StephaneLenclud@49: this.listViewEvents.View = System.Windows.Forms.View.Details;
StephaneLenclud@49: //
StephaneLenclud@49: // columnHeaderUsages
StephaneLenclud@49: //
StephaneLenclud@49: this.columnHeaderUsages.Text = "Usages";
StephaneLenclud@49: this.columnHeaderUsages.Width = 180;
StephaneLenclud@49: //
StephaneLenclud@49: // columnHeaderUsagePage
StephaneLenclud@49: //
StephaneLenclud@49: this.columnHeaderUsagePage.Text = "Usage Page";
StephaneLenclud@49: this.columnHeaderUsagePage.Width = 87;
StephaneLenclud@49: //
StephaneLenclud@49: // columnHeaderUsageCollection
StephaneLenclud@49: //
StephaneLenclud@49: this.columnHeaderUsageCollection.Text = "Usage Collection";
StephaneLenclud@49: this.columnHeaderUsageCollection.Width = 134;
StephaneLenclud@49: //
StephaneLenclud@49: // columnHeaderRepeat
StephaneLenclud@49: //
StephaneLenclud@49: this.columnHeaderRepeat.Text = "Repeat";
StephaneLenclud@49: this.columnHeaderRepeat.Width = 68;
StephaneLenclud@49: //
StephaneLenclud@49: // columnHeaderTime
StephaneLenclud@49: //
StephaneLenclud@49: this.columnHeaderTime.Text = "Time";
StephaneLenclud@49: this.columnHeaderTime.Width = 76;
StephaneLenclud@49: //
StephaneLenclud@49: // buttonClear
StephaneLenclud@49: //
StephaneLenclud@49: this.buttonClear.Location = new System.Drawing.Point(839, 9);
StephaneLenclud@49: this.buttonClear.Name = "buttonClear";
StephaneLenclud@49: this.buttonClear.Size = new System.Drawing.Size(75, 23);
StephaneLenclud@49: this.buttonClear.TabIndex = 3;
StephaneLenclud@49: this.buttonClear.Text = "Clear";
StephaneLenclud@49: this.buttonClear.UseVisualStyleBackColor = true;
StephaneLenclud@49: this.buttonClear.Click += new System.EventHandler(this.buttonClear_Click);
StephaneLenclud@49: //
StephaneLenclud@49: // columnHeaderInputReport
StephaneLenclud@49: //
StephaneLenclud@49: this.columnHeaderInputReport.Text = "Input Report";
StephaneLenclud@49: this.columnHeaderInputReport.Width = 176;
StephaneLenclud@49: //
StephaneLenclud@49: // MainForm
StephaneLenclud@49: //
StephaneLenclud@49: this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
StephaneLenclud@49: this.BackColor = System.Drawing.SystemColors.Control;
StephaneLenclud@49: this.ClientSize = new System.Drawing.Size(926, 393);
StephaneLenclud@49: this.Controls.Add(this.buttonClear);
StephaneLenclud@49: this.Controls.Add(this.listViewEvents);
StephaneLenclud@49: this.Controls.Add(this.labelDeviceName);
StephaneLenclud@49: this.Controls.Add(this.labelButtonName);
StephaneLenclud@49: this.Name = "MainForm";
StephaneLenclud@49: this.Text = "Remote Control Sample";
StephaneLenclud@49: this.Load += new System.EventHandler(this.Form1_Load);
StephaneLenclud@49: this.ResumeLayout(false);
StephaneLenclud@49: this.PerformLayout();
sl@0:
sl@0: }
sl@6: #endregion Windows Form Designer generated code
sl@0:
sl@0: ///
sl@0: /// The main entry point for the application.
sl@0: ///
sl@0: [STAThread]
sl@6: static void Main()
sl@0: {
sl@36: Application.Run(new MainForm());
sl@0: }
sl@0:
sl@0: private void Form1_Load(object sender, System.EventArgs e)
sl@0: {
sl@15: _remote = new RemoteControlDevice(this.Handle);
sl@15: _remote.ButtonPressed += new Devices.RemoteControl.RemoteControlDevice.RemoteControlDeviceEventHandler(_remote_ButtonPressed);
sl@41: _remote.iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
sl@0: }
sl@0:
sl@41: public void HandleHidEventThreadSafe(object aSender, Hid.HidEvent aHidEvent)
sl@40: {
sl@42: if (aHidEvent.IsStray)
sl@42: {
sl@42: //Stray event just ignore it
sl@42: return;
sl@42: }
sl@42:
sl@41: if (this.InvokeRequired)
sl@41: {
sl@41: //Not in the proper thread, invoke ourselves
sl@41: OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
sl@41: this.Invoke(d, new object[] { aSender, aHidEvent });
sl@41: }
sl@41: else
sl@41: {
sl@41: //We are in the proper thread
sl@42: listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
sl@41: }
sl@40: }
sl@0:
sl@0: protected override void WndProc(ref Message message)
sl@0: {
sl@15: if (_remote != null)
sl@15: {
sl@15: _remote.ProcessMessage(message);
sl@15: }
sl@0: base.WndProc(ref message);
sl@0: }
sl@0:
sl@19: private bool _remote_ButtonPressed(object sender, RemoteControlEventArgs e)
sl@0: {
sl@41: //Set text from here was disabled because of threading issues
sl@41: //That whole thing should be removed anyway
sl@19: bool processed = false;
sl@0: _timer.Enabled = false;
sl@3: if (e.Button != RemoteControlButton.Unknown)
sl@3: {
sl@41: //labelButtonName.Text = e.Button.ToString();
sl@19: processed = true;
sl@3: }
sl@30: else if (e.MceButton != Hid.UsageTables.WindowsMediaCenterRemoteControl.Null)
sl@3: {
sl@5: //Display MCE button name
sl@41: //labelButtonName.Text = e.MceButton.ToString();
sl@5: //Check if this is an HP extension
sl@31: if (Enum.IsDefined(typeof(Hid.UsageTables.HpWindowsMediaCenterRemoteControl), (ushort)e.MceButton))
sl@5: {
sl@5: //Also display HP button name
sl@41: //labelButtonName.Text += " / HP:" + ((Hid.UsageTables.HpWindowsMediaCenterRemoteControl)e.MceButton).ToString();
sl@6: }
sl@19:
sl@40: processed = true;
sl@19: }
sl@19: else if (e.ConsumerControl != Hid.UsageTables.ConsumerControl.Null)
sl@19: {
sl@19: //Display consumer control name
sl@41: //labelButtonName.Text = e.ConsumerControl.ToString();
sl@19: processed = true;
sl@3: }
sl@3: else
sl@3: {
sl@41: //labelButtonName.Text = "Unknown";
sl@3: }
sl@41: //labelDeviceName.Text = e.Device.ToString();
sl@0: _timer.Enabled = true;
sl@19: return processed;
sl@0: }
sl@0:
sl@0: private void _timer_Tick(object sender, EventArgs e)
sl@0: {
sl@0: _timer.Enabled = false;
sl@38: labelButtonName.Text = "Ready...";
sl@0: }
sl@38:
StephaneLenclud@49: private void buttonClear_Click(object sender, EventArgs e)
StephaneLenclud@49: {
StephaneLenclud@49: listViewEvents.Items.Clear();
StephaneLenclud@49: }
StephaneLenclud@49:
sl@0: }
sl@0: }