# HG changeset patch # User StephaneLenclud # Date 1426699897 -3600 # Node ID 791786747ba62c000ca7eb9519bc3dc077440092 # Parent 66a68098a4d13c44a3b6d35c800fa5bea4e4a179 Support Green Start launch file selection and bring to foreground feature. Fixing Visual Studio issues with multiple MainForm files. diff -r 66a68098a4d1 -r 791786747ba6 Server/App.config --- a/Server/App.config Tue Mar 17 20:12:00 2015 +0100 +++ b/Server/App.config Wed Mar 18 18:31:37 2015 +0100 @@ -25,6 +25,9 @@ False + + None + diff -r 66a68098a4d1 -r 791786747ba6 Server/MainForm.Designer.cs --- a/Server/MainForm.Designer.cs Tue Mar 17 20:12:00 2015 +0100 +++ b/Server/MainForm.Designer.cs Wed Mar 18 18:31:37 2015 +0100 @@ -85,20 +85,24 @@ this.checkBoxScaleToFit = new System.Windows.Forms.CheckBox(); this.checkBoxInverseColors = new System.Windows.Forms.CheckBox(); this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox(); + this.tabPageAudio = new System.Windows.Forms.TabPage(); + this.labelDefaultAudioDevice = new System.Windows.Forms.Label(); + this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox(); + this.checkBoxMute = new System.Windows.Forms.CheckBox(); + this.trackBarMasterVolume = new System.Windows.Forms.TrackBar(); + this.tabPageInput = new System.Windows.Forms.TabPage(); + this.labelStartFileName = new System.Windows.Forms.Label(); + this.buttonSelectFile = new System.Windows.Forms.Button(); this.tabPageApp = new System.Windows.Forms.TabPage(); this.checkBoxStartMinimized = new System.Windows.Forms.CheckBox(); this.checkBoxMinimizeToTray = new System.Windows.Forms.CheckBox(); this.checkBoxAutoStart = new System.Windows.Forms.CheckBox(); this.buttonUpdate = new System.Windows.Forms.Button(); - this.tabPageAudio = new System.Windows.Forms.TabPage(); - this.labelDefaultAudioDevice = new System.Windows.Forms.Label(); - this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox(); - this.checkBoxMute = new System.Windows.Forms.CheckBox(); - this.trackBarMasterVolume = new System.Windows.Forms.TrackBar(); this.labelFontWidth = new System.Windows.Forms.Label(); this.labelFontHeight = new System.Windows.Forms.Label(); this.pictureBoxDemo = new System.Windows.Forms.PictureBox(); this.toolTip = new System.Windows.Forms.ToolTip(this.components); + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); this.panelDisplay.SuspendLayout(); this.tableLayoutPanel.SuspendLayout(); this.statusStrip.SuspendLayout(); @@ -107,9 +111,10 @@ ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit(); this.tabControl.SuspendLayout(); this.tabPageDesign.SuspendLayout(); - this.tabPageApp.SuspendLayout(); this.tabPageAudio.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBarMasterVolume)).BeginInit(); + this.tabPageInput.SuspendLayout(); + this.tabPageApp.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).BeginInit(); this.SuspendLayout(); // @@ -511,6 +516,7 @@ this.tabControl.Controls.Add(this.tabPageClients); this.tabControl.Controls.Add(this.tabPageDesign); this.tabControl.Controls.Add(this.tabPageAudio); + this.tabControl.Controls.Add(this.tabPageInput); this.tabControl.Controls.Add(this.tabPageApp); this.tabControl.Location = new System.Drawing.Point(12, 139); this.tabControl.Name = "tabControl"; @@ -631,66 +637,6 @@ this.checkBoxReverseScreen.UseVisualStyleBackColor = true; this.checkBoxReverseScreen.CheckedChanged += new System.EventHandler(this.checkBoxReverseScreen_CheckedChanged); // - // tabPageApp - // - this.tabPageApp.Controls.Add(this.checkBoxStartMinimized); - this.tabPageApp.Controls.Add(this.checkBoxMinimizeToTray); - this.tabPageApp.Controls.Add(this.checkBoxAutoStart); - this.tabPageApp.Controls.Add(this.buttonUpdate); - this.tabPageApp.Location = new System.Drawing.Point(4, 22); - this.tabPageApp.Name = "tabPageApp"; - this.tabPageApp.Padding = new System.Windows.Forms.Padding(3); - this.tabPageApp.Size = new System.Drawing.Size(592, 242); - this.tabPageApp.TabIndex = 4; - this.tabPageApp.Text = "Application"; - this.tabPageApp.UseVisualStyleBackColor = true; - // - // checkBoxStartMinimized - // - this.checkBoxStartMinimized.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.checkBoxStartMinimized.AutoSize = true; - this.checkBoxStartMinimized.Location = new System.Drawing.Point(8, 144); - this.checkBoxStartMinimized.Name = "checkBoxStartMinimized"; - this.checkBoxStartMinimized.Size = new System.Drawing.Size(96, 17); - this.checkBoxStartMinimized.TabIndex = 16; - this.checkBoxStartMinimized.Text = "Start minimized"; - this.checkBoxStartMinimized.UseVisualStyleBackColor = true; - this.checkBoxStartMinimized.CheckedChanged += new System.EventHandler(this.checkBoxStartMinimized_CheckedChanged); - // - // checkBoxMinimizeToTray - // - this.checkBoxMinimizeToTray.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.checkBoxMinimizeToTray.AutoSize = true; - this.checkBoxMinimizeToTray.Location = new System.Drawing.Point(8, 167); - this.checkBoxMinimizeToTray.Name = "checkBoxMinimizeToTray"; - this.checkBoxMinimizeToTray.Size = new System.Drawing.Size(133, 17); - this.checkBoxMinimizeToTray.TabIndex = 15; - this.checkBoxMinimizeToTray.Text = "Minimize to system tray"; - this.checkBoxMinimizeToTray.UseVisualStyleBackColor = true; - this.checkBoxMinimizeToTray.CheckedChanged += new System.EventHandler(this.checkBoxMinimizeToTray_CheckedChanged); - // - // checkBoxAutoStart - // - this.checkBoxAutoStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.checkBoxAutoStart.AutoSize = true; - this.checkBoxAutoStart.Location = new System.Drawing.Point(8, 190); - this.checkBoxAutoStart.Name = "checkBoxAutoStart"; - this.checkBoxAutoStart.Size = new System.Drawing.Size(143, 17); - this.checkBoxAutoStart.TabIndex = 14; - this.checkBoxAutoStart.Text = "Run on Windows startup"; - this.checkBoxAutoStart.UseVisualStyleBackColor = true; - this.checkBoxAutoStart.CheckedChanged += new System.EventHandler(this.checkBoxAutoStart_CheckedChanged); - // - // buttonUpdate - // - this.buttonUpdate.Location = new System.Drawing.Point(6, 213); - this.buttonUpdate.Name = "buttonUpdate"; - this.buttonUpdate.Size = new System.Drawing.Size(75, 23); - this.buttonUpdate.TabIndex = 0; - this.buttonUpdate.Text = "Update"; - this.buttonUpdate.UseVisualStyleBackColor = true; - this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); - // // tabPageAudio // this.tabPageAudio.Controls.Add(this.labelDefaultAudioDevice); @@ -753,6 +699,97 @@ this.toolTip.SetToolTip(this.trackBarMasterVolume, "Master Volume"); this.trackBarMasterVolume.Scroll += new System.EventHandler(this.trackBarMasterVolume_Scroll); // + // tabPageInput + // + this.tabPageInput.Controls.Add(this.labelStartFileName); + this.tabPageInput.Controls.Add(this.buttonSelectFile); + this.tabPageInput.Location = new System.Drawing.Point(4, 22); + this.tabPageInput.Name = "tabPageInput"; + this.tabPageInput.Padding = new System.Windows.Forms.Padding(3); + this.tabPageInput.Size = new System.Drawing.Size(592, 242); + this.tabPageInput.TabIndex = 6; + this.tabPageInput.Text = "Input"; + this.tabPageInput.UseVisualStyleBackColor = true; + // + // labelStartFileName + // + this.labelStartFileName.AutoSize = true; + this.labelStartFileName.Location = new System.Drawing.Point(37, 11); + this.labelStartFileName.Name = "labelStartFileName"; + this.labelStartFileName.Size = new System.Drawing.Size(33, 13); + this.labelStartFileName.TabIndex = 1; + this.labelStartFileName.Text = "None"; + // + // buttonSelectFile + // + this.buttonSelectFile.Location = new System.Drawing.Point(6, 6); + this.buttonSelectFile.Name = "buttonSelectFile"; + this.buttonSelectFile.Size = new System.Drawing.Size(25, 23); + this.buttonSelectFile.TabIndex = 0; + this.buttonSelectFile.Text = "..."; + this.buttonSelectFile.UseVisualStyleBackColor = true; + this.buttonSelectFile.Click += new System.EventHandler(this.buttonSelectFile_Click); + // + // tabPageApp + // + this.tabPageApp.Controls.Add(this.checkBoxStartMinimized); + this.tabPageApp.Controls.Add(this.checkBoxMinimizeToTray); + this.tabPageApp.Controls.Add(this.checkBoxAutoStart); + this.tabPageApp.Controls.Add(this.buttonUpdate); + this.tabPageApp.Location = new System.Drawing.Point(4, 22); + this.tabPageApp.Name = "tabPageApp"; + this.tabPageApp.Padding = new System.Windows.Forms.Padding(3); + this.tabPageApp.Size = new System.Drawing.Size(592, 242); + this.tabPageApp.TabIndex = 4; + this.tabPageApp.Text = "Application"; + this.tabPageApp.UseVisualStyleBackColor = true; + // + // checkBoxStartMinimized + // + this.checkBoxStartMinimized.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxStartMinimized.AutoSize = true; + this.checkBoxStartMinimized.Location = new System.Drawing.Point(8, 144); + this.checkBoxStartMinimized.Name = "checkBoxStartMinimized"; + this.checkBoxStartMinimized.Size = new System.Drawing.Size(96, 17); + this.checkBoxStartMinimized.TabIndex = 16; + this.checkBoxStartMinimized.Text = "Start minimized"; + this.checkBoxStartMinimized.UseVisualStyleBackColor = true; + this.checkBoxStartMinimized.CheckedChanged += new System.EventHandler(this.checkBoxStartMinimized_CheckedChanged); + // + // checkBoxMinimizeToTray + // + this.checkBoxMinimizeToTray.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxMinimizeToTray.AutoSize = true; + this.checkBoxMinimizeToTray.Location = new System.Drawing.Point(8, 167); + this.checkBoxMinimizeToTray.Name = "checkBoxMinimizeToTray"; + this.checkBoxMinimizeToTray.Size = new System.Drawing.Size(133, 17); + this.checkBoxMinimizeToTray.TabIndex = 15; + this.checkBoxMinimizeToTray.Text = "Minimize to system tray"; + this.checkBoxMinimizeToTray.UseVisualStyleBackColor = true; + this.checkBoxMinimizeToTray.CheckedChanged += new System.EventHandler(this.checkBoxMinimizeToTray_CheckedChanged); + // + // checkBoxAutoStart + // + this.checkBoxAutoStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.checkBoxAutoStart.AutoSize = true; + this.checkBoxAutoStart.Location = new System.Drawing.Point(8, 190); + this.checkBoxAutoStart.Name = "checkBoxAutoStart"; + this.checkBoxAutoStart.Size = new System.Drawing.Size(143, 17); + this.checkBoxAutoStart.TabIndex = 14; + this.checkBoxAutoStart.Text = "Run on Windows startup"; + this.checkBoxAutoStart.UseVisualStyleBackColor = true; + this.checkBoxAutoStart.CheckedChanged += new System.EventHandler(this.checkBoxAutoStart_CheckedChanged); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(6, 213); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(75, 23); + this.buttonUpdate.TabIndex = 0; + this.buttonUpdate.Text = "Update"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // // labelFontWidth // this.labelFontWidth.AutoSize = true; @@ -779,6 +816,10 @@ this.pictureBoxDemo.TabIndex = 21; this.pictureBoxDemo.TabStop = false; // + // openFileDialog + // + this.openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -811,11 +852,13 @@ this.tabControl.ResumeLayout(false); this.tabPageDesign.ResumeLayout(false); this.tabPageDesign.PerformLayout(); - this.tabPageApp.ResumeLayout(false); - this.tabPageApp.PerformLayout(); this.tabPageAudio.ResumeLayout(false); this.tabPageAudio.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.trackBarMasterVolume)).EndInit(); + this.tabPageInput.ResumeLayout(false); + this.tabPageInput.PerformLayout(); + this.tabPageApp.ResumeLayout(false); + this.tabPageApp.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -884,6 +927,10 @@ private System.Windows.Forms.CheckBox checkBoxMute; private System.Windows.Forms.CheckBox checkBoxShowVolumeLabel; private System.Windows.Forms.Label labelDefaultAudioDevice; + private System.Windows.Forms.TabPage tabPageInput; + private System.Windows.Forms.Button buttonSelectFile; + private System.Windows.Forms.OpenFileDialog openFileDialog; + private System.Windows.Forms.Label labelStartFileName; } } diff -r 66a68098a4d1 -r 791786747ba6 Server/MainForm.Hid.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Server/MainForm.Hid.cs Wed Mar 18 18:31:37 2015 +0100 @@ -0,0 +1,158 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Windows.Forms; +// +using Hid = SharpLib.Hid; +using SharpLib.Win32; + +namespace SharpDisplayManager +{ + [System.ComponentModel.DesignerCategory("Code")] + public class MainFormHid: Form + { + + [DllImport("USER32.DLL")] + public static extern bool SetForegroundWindow(IntPtr hWnd); + + + public delegate void OnHidEventDelegate(object aSender, Hid.Event aHidEvent); + + /// + /// Use notably to handle green start key from IR remote control + /// + private Hid.Handler iHidHandler; + + protected void RegisterHidDevices() + { + // Register the input device to receive the commands from the + // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp + // for the vendor defined usage page. + + RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5]; + + int i = 0; + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl; + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl; + rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].hwndTarget = Handle; + + i++; + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl; + rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].hwndTarget = Handle; + + i++; + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection; + rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].hwndTarget = Handle; + + i++; + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl; + rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].hwndTarget = Handle; + + i++; + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad; + rid[i].dwFlags = Const.RIDEV_INPUTSINK; + rid[i].hwndTarget = Handle; + + //i++; + //rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; + //rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard; + //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; + //rid[i].hwndTarget = Handle; + + //i++; + //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls; + //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse; + //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; + //rid[i].hwndTarget = aHWND; + + + iHidHandler = new SharpLib.Hid.Handler(rid); + if (!iHidHandler.IsRegistered) + { + Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString()); + } + iHidHandler.OnHidEvent += HandleHidEventThreadSafe; + } + + public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) + { + if (aHidEvent.IsStray) + { + //Stray event just ignore it + return; + } + + if (this.InvokeRequired) + { + //Not in the proper thread, invoke ourselves + OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); + this.Invoke(d, new object[] { aSender, aHidEvent }); + } + else + { + //We are in the proper thread + if (aHidEvent.Usages.Count > 0 + && aHidEvent.UsagePage == (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl + && aHidEvent.Usages[0] == (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart) + //&& aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer + //&& aHidEvent.Usages[0] == (ushort)Hid.Usage.ConsumerControl.ThinkPadFullscreenMagnifier) + + { + //First check if the process we want to launch already exists + string procName = Path.GetFileNameWithoutExtension(Properties.Settings.Default.StartFileName); + Process[] existingProcesses = Process.GetProcessesByName(procName); + if (existingProcesses == null || existingProcesses.Length==0) + { + // Process do not exists just try to launch it + ProcessStartInfo start = new ProcessStartInfo(); + // Enter in the command line arguments, everything you would enter after the executable name itself + //start.Arguments = arguments; + // Enter the executable to run, including the complete path + start.FileName = Properties.Settings.Default.StartFileName; + start.WindowStyle = ProcessWindowStyle.Normal; + start.CreateNoWindow = true; + start.UseShellExecute = true; + // Run the external process & wait for it to finish + Process proc = Process.Start(start); + + //SL: We could have used that too + //Shell32.Shell shell = new Shell32.Shell(); + //shell.ShellExecute(Properties.Settings.Default.StartFileName); + } + else + { + SetForegroundWindow(existingProcesses[0].MainWindowHandle); + } + } + } + } + + + protected override void WndProc(ref Message message) + { + switch (message.Msg) + { + case Const.WM_INPUT: + //Returning zero means we processed that message. + message.Result = new IntPtr(0); + iHidHandler.ProcessInput(ref message); + break; + } + //Is that needed? Check the docs. + base.WndProc(ref message); + } + } +} diff -r 66a68098a4d1 -r 791786747ba6 Server/MainForm.cs --- a/Server/MainForm.cs Tue Mar 17 20:12:00 2015 +0100 +++ b/Server/MainForm.cs Wed Mar 18 18:31:37 2015 +0100 @@ -63,7 +63,8 @@ /// /// Our Display manager main form /// - public partial class MainForm : Form, IMMNotificationClient + [System.ComponentModel.DesignerCategory("Form")] + public partial class MainForm : MainFormHid, IMMNotificationClient { DateTime LastTickTime; Display iDisplay; @@ -996,6 +997,7 @@ checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray; checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized; + labelStartFileName.Text = Properties.Settings.Default.StartFileName; checkBoxReverseScreen.Checked = cds.ReverseScreen; checkBoxInverseColors.Checked = cds.InverseColors; checkBoxShowVolumeLabel.Checked = cds.ShowVolumeLabel; @@ -2023,6 +2025,26 @@ //We need to re-create our bitmap. iCreateBitmap = true; } + + /// + /// + /// + /// + /// + private void buttonSelectFile_Click(object sender, EventArgs e) + { + //openFileDialog1.InitialDirectory = "c:\\"; + //openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; + //openFileDialog.FilterIndex = 1; + openFileDialog.RestoreDirectory = true; + + if (DlgBox.ShowDialog(openFileDialog) == DialogResult.OK) + { + labelStartFileName.Text = openFileDialog.FileName; + Properties.Settings.Default.StartFileName = openFileDialog.FileName; + Properties.Settings.Default.Save(); + } + } } /// diff -r 66a68098a4d1 -r 791786747ba6 Server/MainForm.resx --- a/Server/MainForm.resx Tue Mar 17 20:12:00 2015 +0100 +++ b/Server/MainForm.resx Wed Mar 18 18:31:37 2015 +0100 @@ -129,6 +129,9 @@ 315, 17 + + 405, 17 + diff -r 66a68098a4d1 -r 791786747ba6 Server/MainFormHid.cs --- a/Server/MainFormHid.cs Tue Mar 17 20:12:00 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Diagnostics; -using System.Runtime.InteropServices; -using System.Windows.Forms; -// -using Hid = SharpLib.Hid; -using SharpLib.Win32; - -namespace SharpDisplayManager -{ - [System.ComponentModel.DesignerCategory("Code")] - public partial class MainForm: Form - { - public delegate void OnHidEventDelegate(object aSender, Hid.Event aHidEvent); - - /// - /// Use notably to handle green start key from IR remote control - /// - private Hid.Handler iHidHandler; - - void RegisterHidDevices() - { - // Register the input device to receive the commands from the - // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp - // for the vendor defined usage page. - - RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5]; - - int i = 0; - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl; - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; - rid[i].hwndTarget = Handle; - - i++; - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; - rid[i].hwndTarget = Handle; - - i++; - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; - rid[i].hwndTarget = Handle; - - i++; - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; - rid[i].hwndTarget = Handle; - - i++; - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad; - rid[i].dwFlags = Const.RIDEV_INPUTSINK; - rid[i].hwndTarget = Handle; - - //i++; - //rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; - //rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard; - //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; - //rid[i].hwndTarget = Handle; - - //i++; - //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls; - //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse; - //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; - //rid[i].hwndTarget = aHWND; - - - iHidHandler = new SharpLib.Hid.Handler(rid); - if (!iHidHandler.IsRegistered) - { - Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString()); - } - iHidHandler.OnHidEvent += HandleHidEventThreadSafe; - } - - public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) - { - if (aHidEvent.IsStray) - { - //Stray event just ignore it - return; - } - - if (this.InvokeRequired) - { - //Not in the proper thread, invoke ourselves - OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); - this.Invoke(d, new object[] { aSender, aHidEvent }); - } - else - { - //We are in the proper thread - //listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem()); - //toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName; - - if (aHidEvent.Usages.Count > 0 - && aHidEvent.UsagePage == (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl - && aHidEvent.Usages[0] == (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart) - { - //Hard coding it all for now - // Prepare the process to run - ProcessStartInfo start = new ProcessStartInfo(); - // Enter in the command line arguments, everything you would enter after the executable name itself - //start.Arguments = arguments; - // Enter the executable to run, including the complete path - start.FileName = "C:\\Program Files (x86)\\Team MediaPortal\\MediaPortal\\MediaPortal.exe"; - // Do you want to show a console window? - start.WindowStyle = ProcessWindowStyle.Hidden; - start.CreateNoWindow = true; - // Run the external process & wait for it to finish - Process proc = Process.Start(start); - } - } - } - - protected override void WndProc(ref Message message) - { - switch (message.Msg) - { - case Const.WM_INPUT: - //Returning zero means we processed that message. - message.Result = new IntPtr(0); - iHidHandler.ProcessInput(ref message); - break; - } - //Is that needed? Check the docs. - base.WndProc(ref message); - } - - - } -} diff -r 66a68098a4d1 -r 791786747ba6 Server/Properties/Settings.Designer.cs --- a/Server/Properties/Settings.Designer.cs Tue Mar 17 20:12:00 2015 +0100 +++ b/Server/Properties/Settings.Designer.cs Wed Mar 18 18:31:37 2015 +0100 @@ -12,7 +12,7 @@ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -93,5 +93,17 @@ this["StartMinimized"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("None")] + public string StartFileName { + get { + return ((string)(this["StartFileName"])); + } + set { + this["StartFileName"] = value; + } + } } } diff -r 66a68098a4d1 -r 791786747ba6 Server/Properties/Settings.settings --- a/Server/Properties/Settings.settings Tue Mar 17 20:12:00 2015 +0100 +++ b/Server/Properties/Settings.settings Wed Mar 18 18:31:37 2015 +0100 @@ -20,5 +20,8 @@ False + + None + \ No newline at end of file diff -r 66a68098a4d1 -r 791786747ba6 Server/SharpDisplayManager.csproj --- a/Server/SharpDisplayManager.csproj Tue Mar 17 20:12:00 2015 +0100 +++ b/Server/SharpDisplayManager.csproj Wed Mar 18 18:31:37 2015 +0100 @@ -131,12 +131,16 @@ - + + MainForm.cs + - + + Form + MainForm.cs @@ -237,6 +241,15 @@ False True + + {50A7E9B0-70EF-11D1-B75A-00A0C90564FE} + 1 + 0 + 0 + tlbimp + False + True +