Adding missing source file.
authorStephaneLenclud
Tue, 17 Mar 2015 20:12:00 +0100
changeset 12566a68098a4d1
parent 124 b3cc1093c22b
child 126 791786747ba6
Adding missing source file.
Updating SharpLibHid.
Now Green Start works better when app in background.
Server/MainFormHid.cs
Server/SharpDisplayManager.csproj
Server/packages.config
SharpDisplayManager.sln
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/Server/MainFormHid.cs	Tue Mar 17 20:12:00 2015 +0100
     1.3 @@ -0,0 +1,140 @@
     1.4 +using System;
     1.5 +using System.Collections.Generic;
     1.6 +using System.Linq;
     1.7 +using System.Text;
     1.8 +using System.Threading.Tasks;
     1.9 +using System.Diagnostics;
    1.10 +using System.Runtime.InteropServices;
    1.11 +using System.Windows.Forms;
    1.12 +//
    1.13 +using Hid = SharpLib.Hid;
    1.14 +using SharpLib.Win32;
    1.15 +
    1.16 +namespace SharpDisplayManager
    1.17 +{
    1.18 +	[System.ComponentModel.DesignerCategory("Code")]
    1.19 +	public partial class MainForm: Form
    1.20 +	{
    1.21 +		public delegate void OnHidEventDelegate(object aSender, Hid.Event aHidEvent);
    1.22 +
    1.23 +		/// <summary>
    1.24 +		/// Use notably to handle green start key from IR remote control
    1.25 +		/// </summary>
    1.26 +		private Hid.Handler iHidHandler;
    1.27 +
    1.28 +		void RegisterHidDevices()
    1.29 +		{
    1.30 +			// Register the input device to receive the commands from the
    1.31 +			// remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp
    1.32 +			// for the vendor defined usage page.
    1.33 +
    1.34 +			RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5];
    1.35 +
    1.36 +			int i = 0;
    1.37 +			rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl;
    1.38 +			rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl;
    1.39 +			rid[i].dwFlags = Const.RIDEV_INPUTSINK;
    1.40 +			rid[i].hwndTarget = Handle;
    1.41 +
    1.42 +			i++;
    1.43 +			rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
    1.44 +			rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl;
    1.45 +			rid[i].dwFlags = Const.RIDEV_INPUTSINK;
    1.46 +			rid[i].hwndTarget = Handle;
    1.47 +
    1.48 +			i++;
    1.49 +			rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer;
    1.50 +			rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection;
    1.51 +			rid[i].dwFlags = Const.RIDEV_INPUTSINK;
    1.52 +			rid[i].hwndTarget = Handle;
    1.53 +
    1.54 +			i++;
    1.55 +			rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
    1.56 +			rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl;
    1.57 +			rid[i].dwFlags = Const.RIDEV_INPUTSINK;
    1.58 +			rid[i].hwndTarget = Handle;
    1.59 +
    1.60 +			i++;
    1.61 +			rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
    1.62 +			rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad;
    1.63 +			rid[i].dwFlags = Const.RIDEV_INPUTSINK;
    1.64 +			rid[i].hwndTarget = Handle;
    1.65 +
    1.66 +			//i++;
    1.67 +			//rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls;
    1.68 +			//rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard;
    1.69 +			//rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
    1.70 +			//rid[i].hwndTarget = Handle;
    1.71 +
    1.72 +			//i++;
    1.73 +			//rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls;
    1.74 +			//rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse;
    1.75 +			//rid[i].dwFlags = Const.RIDEV_EXINPUTSINK;
    1.76 +			//rid[i].hwndTarget = aHWND;
    1.77 +
    1.78 +
    1.79 +			iHidHandler = new SharpLib.Hid.Handler(rid);
    1.80 +			if (!iHidHandler.IsRegistered)
    1.81 +			{
    1.82 +				Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString());
    1.83 +			}
    1.84 +			iHidHandler.OnHidEvent += HandleHidEventThreadSafe;
    1.85 +		}
    1.86 +
    1.87 +		public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent)
    1.88 +		{
    1.89 +			if (aHidEvent.IsStray)
    1.90 +			{
    1.91 +				//Stray event just ignore it
    1.92 +				return;
    1.93 +			}
    1.94 +
    1.95 +			if (this.InvokeRequired)
    1.96 +			{
    1.97 +				//Not in the proper thread, invoke ourselves
    1.98 +				OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe);
    1.99 +				this.Invoke(d, new object[] { aSender, aHidEvent });
   1.100 +			}
   1.101 +			else
   1.102 +			{
   1.103 +				//We are in the proper thread
   1.104 +				//listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem());
   1.105 +				//toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName;
   1.106 +
   1.107 +				if (aHidEvent.Usages.Count > 0
   1.108 +					&& aHidEvent.UsagePage == (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl
   1.109 +					&& aHidEvent.Usages[0] == (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart)
   1.110 +				{
   1.111 +					//Hard coding it all for now
   1.112 +					// Prepare the process to run
   1.113 +					ProcessStartInfo start = new ProcessStartInfo();
   1.114 +					// Enter in the command line arguments, everything you would enter after the executable name itself
   1.115 +					//start.Arguments = arguments; 
   1.116 +					// Enter the executable to run, including the complete path
   1.117 +					start.FileName = "C:\\Program Files (x86)\\Team MediaPortal\\MediaPortal\\MediaPortal.exe";
   1.118 +					// Do you want to show a console window?
   1.119 +					start.WindowStyle = ProcessWindowStyle.Hidden;
   1.120 +					start.CreateNoWindow = true;
   1.121 +					// Run the external process & wait for it to finish
   1.122 +					Process proc = Process.Start(start);
   1.123 +				}
   1.124 +			}
   1.125 +		}
   1.126 +
   1.127 +		protected override void WndProc(ref Message message)
   1.128 +		{
   1.129 +			switch (message.Msg)
   1.130 +			{
   1.131 +				case Const.WM_INPUT:
   1.132 +					//Returning zero means we processed that message.
   1.133 +					message.Result = new IntPtr(0);
   1.134 +					iHidHandler.ProcessInput(ref message);
   1.135 +					break;
   1.136 +			}
   1.137 +			//Is that needed? Check the docs.
   1.138 +			base.WndProc(ref message);
   1.139 +		}
   1.140 +
   1.141 +
   1.142 +	}
   1.143 +}
     2.1 --- a/Server/SharpDisplayManager.csproj	Sun Mar 15 22:08:30 2015 +0100
     2.2 +++ b/Server/SharpDisplayManager.csproj	Tue Mar 17 20:12:00 2015 +0100
     2.3 @@ -32,7 +32,7 @@
     2.4      <WebPage>index.htm</WebPage>
     2.5      <OpenBrowserOnPublish>false</OpenBrowserOnPublish>
     2.6      <ApplicationRevision>1</ApplicationRevision>
     2.7 -    <ApplicationVersion>0.3.0.%2a</ApplicationVersion>
     2.8 +    <ApplicationVersion>0.3.1.%2a</ApplicationVersion>
     2.9      <UseApplicationTrust>false</UseApplicationTrust>
    2.10      <CreateDesktopShortcut>true</CreateDesktopShortcut>
    2.11      <PublishWizardCompleted>true</PublishWizardCompleted>
    2.12 @@ -109,8 +109,9 @@
    2.13      <Reference Include="NAudio">
    2.14        <HintPath>..\packages\NAudio.1.7.2\lib\net35\NAudio.dll</HintPath>
    2.15      </Reference>
    2.16 -    <Reference Include="SharpLibHid">
    2.17 -      <HintPath>..\packages\SharpLibHid.1.0.0\lib\net20\SharpLibHid.dll</HintPath>
    2.18 +    <Reference Include="SharpLibHid, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
    2.19 +      <SpecificVersion>False</SpecificVersion>
    2.20 +      <HintPath>..\packages\SharpLibHid.1.0.1\lib\net20\SharpLibHid.dll</HintPath>
    2.21      </Reference>
    2.22      <Reference Include="System" />
    2.23      <Reference Include="System.Configuration" />
    2.24 @@ -135,9 +136,7 @@
    2.25      <Compile Include="DialogBox.cs" />
    2.26      <Compile Include="Display.cs" />
    2.27      <Compile Include="DisplaySettings.cs" />
    2.28 -    <Compile Include="MainForm.cs">
    2.29 -      <SubType>Form</SubType>
    2.30 -    </Compile>
    2.31 +    <Compile Include="MainForm.cs" />
    2.32      <Compile Include="MainForm.Designer.cs">
    2.33        <DependentUpon>MainForm.cs</DependentUpon>
    2.34      </Compile>
     3.1 --- a/Server/packages.config	Sun Mar 15 22:08:30 2015 +0100
     3.2 +++ b/Server/packages.config	Tue Mar 17 20:12:00 2015 +0100
     3.3 @@ -1,5 +1,5 @@
     3.4  <?xml version="1.0" encoding="utf-8"?>
     3.5  <packages>
     3.6    <package id="NAudio" version="1.7.2" targetFramework="net45" />
     3.7 -  <package id="SharpLibHid" version="1.0.0" targetFramework="net45" />
     3.8 +  <package id="SharpLibHid" version="1.0.1" targetFramework="net45" />
     3.9  </packages>
    3.10 \ No newline at end of file
     4.1 --- a/SharpDisplayManager.sln	Sun Mar 15 22:08:30 2015 +0100
     4.2 +++ b/SharpDisplayManager.sln	Tue Mar 17 20:12:00 2015 +0100
     4.3 @@ -1,6 +1,6 @@
     4.4  
     4.5  Microsoft Visual Studio Solution File, Format Version 12.00
     4.6 -# Visual Studio 2012
     4.7 +# Visual Studio 2013
     4.8  Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpDisplayManager", "Server\SharpDisplayManager.csproj", "{1DA8C1B3-18C5-4E74-BE4E-0B0E15FBAF49}"
     4.9  EndProject
    4.10  Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpDisplayClient", "Client\SharpDisplayClient.csproj", "{7EE64074-8CDB-4448-B40C-81B75D6B31CD}"