author | StephaneLenclud |
Wed, 18 Mar 2015 18:31:37 +0100 | |
changeset 126 | 791786747ba6 |
parent 125 | 66a68098a4d1 |
child 127 | 75addfa85201 |
1.1 --- a/Server/App.config Tue Mar 17 20:12:00 2015 +0100 1.2 +++ b/Server/App.config Wed Mar 18 18:31:37 2015 +0100 1.3 @@ -25,6 +25,9 @@ 1.4 <setting name="StartMinimized" serializeAs="String"> 1.5 <value>False</value> 1.6 </setting> 1.7 + <setting name="StartFileName" serializeAs="String"> 1.8 + <value>None</value> 1.9 + </setting> 1.10 </SharpDisplayManager.Properties.Settings> 1.11 </userSettings> 1.12 </configuration>
2.1 --- a/Server/MainForm.Designer.cs Tue Mar 17 20:12:00 2015 +0100 2.2 +++ b/Server/MainForm.Designer.cs Wed Mar 18 18:31:37 2015 +0100 2.3 @@ -85,20 +85,24 @@ 2.4 this.checkBoxScaleToFit = new System.Windows.Forms.CheckBox(); 2.5 this.checkBoxInverseColors = new System.Windows.Forms.CheckBox(); 2.6 this.checkBoxReverseScreen = new System.Windows.Forms.CheckBox(); 2.7 + this.tabPageAudio = new System.Windows.Forms.TabPage(); 2.8 + this.labelDefaultAudioDevice = new System.Windows.Forms.Label(); 2.9 + this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox(); 2.10 + this.checkBoxMute = new System.Windows.Forms.CheckBox(); 2.11 + this.trackBarMasterVolume = new System.Windows.Forms.TrackBar(); 2.12 + this.tabPageInput = new System.Windows.Forms.TabPage(); 2.13 + this.labelStartFileName = new System.Windows.Forms.Label(); 2.14 + this.buttonSelectFile = new System.Windows.Forms.Button(); 2.15 this.tabPageApp = new System.Windows.Forms.TabPage(); 2.16 this.checkBoxStartMinimized = new System.Windows.Forms.CheckBox(); 2.17 this.checkBoxMinimizeToTray = new System.Windows.Forms.CheckBox(); 2.18 this.checkBoxAutoStart = new System.Windows.Forms.CheckBox(); 2.19 this.buttonUpdate = new System.Windows.Forms.Button(); 2.20 - this.tabPageAudio = new System.Windows.Forms.TabPage(); 2.21 - this.labelDefaultAudioDevice = new System.Windows.Forms.Label(); 2.22 - this.checkBoxShowVolumeLabel = new System.Windows.Forms.CheckBox(); 2.23 - this.checkBoxMute = new System.Windows.Forms.CheckBox(); 2.24 - this.trackBarMasterVolume = new System.Windows.Forms.TrackBar(); 2.25 this.labelFontWidth = new System.Windows.Forms.Label(); 2.26 this.labelFontHeight = new System.Windows.Forms.Label(); 2.27 this.pictureBoxDemo = new System.Windows.Forms.PictureBox(); 2.28 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 2.29 + this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 2.30 this.panelDisplay.SuspendLayout(); 2.31 this.tableLayoutPanel.SuspendLayout(); 2.32 this.statusStrip.SuspendLayout(); 2.33 @@ -107,9 +111,10 @@ 2.34 ((System.ComponentModel.ISupportInitialize)(this.trackBarBrightness)).BeginInit(); 2.35 this.tabControl.SuspendLayout(); 2.36 this.tabPageDesign.SuspendLayout(); 2.37 - this.tabPageApp.SuspendLayout(); 2.38 this.tabPageAudio.SuspendLayout(); 2.39 ((System.ComponentModel.ISupportInitialize)(this.trackBarMasterVolume)).BeginInit(); 2.40 + this.tabPageInput.SuspendLayout(); 2.41 + this.tabPageApp.SuspendLayout(); 2.42 ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).BeginInit(); 2.43 this.SuspendLayout(); 2.44 // 2.45 @@ -511,6 +516,7 @@ 2.46 this.tabControl.Controls.Add(this.tabPageClients); 2.47 this.tabControl.Controls.Add(this.tabPageDesign); 2.48 this.tabControl.Controls.Add(this.tabPageAudio); 2.49 + this.tabControl.Controls.Add(this.tabPageInput); 2.50 this.tabControl.Controls.Add(this.tabPageApp); 2.51 this.tabControl.Location = new System.Drawing.Point(12, 139); 2.52 this.tabControl.Name = "tabControl"; 2.53 @@ -631,66 +637,6 @@ 2.54 this.checkBoxReverseScreen.UseVisualStyleBackColor = true; 2.55 this.checkBoxReverseScreen.CheckedChanged += new System.EventHandler(this.checkBoxReverseScreen_CheckedChanged); 2.56 // 2.57 - // tabPageApp 2.58 - // 2.59 - this.tabPageApp.Controls.Add(this.checkBoxStartMinimized); 2.60 - this.tabPageApp.Controls.Add(this.checkBoxMinimizeToTray); 2.61 - this.tabPageApp.Controls.Add(this.checkBoxAutoStart); 2.62 - this.tabPageApp.Controls.Add(this.buttonUpdate); 2.63 - this.tabPageApp.Location = new System.Drawing.Point(4, 22); 2.64 - this.tabPageApp.Name = "tabPageApp"; 2.65 - this.tabPageApp.Padding = new System.Windows.Forms.Padding(3); 2.66 - this.tabPageApp.Size = new System.Drawing.Size(592, 242); 2.67 - this.tabPageApp.TabIndex = 4; 2.68 - this.tabPageApp.Text = "Application"; 2.69 - this.tabPageApp.UseVisualStyleBackColor = true; 2.70 - // 2.71 - // checkBoxStartMinimized 2.72 - // 2.73 - this.checkBoxStartMinimized.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 2.74 - this.checkBoxStartMinimized.AutoSize = true; 2.75 - this.checkBoxStartMinimized.Location = new System.Drawing.Point(8, 144); 2.76 - this.checkBoxStartMinimized.Name = "checkBoxStartMinimized"; 2.77 - this.checkBoxStartMinimized.Size = new System.Drawing.Size(96, 17); 2.78 - this.checkBoxStartMinimized.TabIndex = 16; 2.79 - this.checkBoxStartMinimized.Text = "Start minimized"; 2.80 - this.checkBoxStartMinimized.UseVisualStyleBackColor = true; 2.81 - this.checkBoxStartMinimized.CheckedChanged += new System.EventHandler(this.checkBoxStartMinimized_CheckedChanged); 2.82 - // 2.83 - // checkBoxMinimizeToTray 2.84 - // 2.85 - this.checkBoxMinimizeToTray.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 2.86 - this.checkBoxMinimizeToTray.AutoSize = true; 2.87 - this.checkBoxMinimizeToTray.Location = new System.Drawing.Point(8, 167); 2.88 - this.checkBoxMinimizeToTray.Name = "checkBoxMinimizeToTray"; 2.89 - this.checkBoxMinimizeToTray.Size = new System.Drawing.Size(133, 17); 2.90 - this.checkBoxMinimizeToTray.TabIndex = 15; 2.91 - this.checkBoxMinimizeToTray.Text = "Minimize to system tray"; 2.92 - this.checkBoxMinimizeToTray.UseVisualStyleBackColor = true; 2.93 - this.checkBoxMinimizeToTray.CheckedChanged += new System.EventHandler(this.checkBoxMinimizeToTray_CheckedChanged); 2.94 - // 2.95 - // checkBoxAutoStart 2.96 - // 2.97 - this.checkBoxAutoStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 2.98 - this.checkBoxAutoStart.AutoSize = true; 2.99 - this.checkBoxAutoStart.Location = new System.Drawing.Point(8, 190); 2.100 - this.checkBoxAutoStart.Name = "checkBoxAutoStart"; 2.101 - this.checkBoxAutoStart.Size = new System.Drawing.Size(143, 17); 2.102 - this.checkBoxAutoStart.TabIndex = 14; 2.103 - this.checkBoxAutoStart.Text = "Run on Windows startup"; 2.104 - this.checkBoxAutoStart.UseVisualStyleBackColor = true; 2.105 - this.checkBoxAutoStart.CheckedChanged += new System.EventHandler(this.checkBoxAutoStart_CheckedChanged); 2.106 - // 2.107 - // buttonUpdate 2.108 - // 2.109 - this.buttonUpdate.Location = new System.Drawing.Point(6, 213); 2.110 - this.buttonUpdate.Name = "buttonUpdate"; 2.111 - this.buttonUpdate.Size = new System.Drawing.Size(75, 23); 2.112 - this.buttonUpdate.TabIndex = 0; 2.113 - this.buttonUpdate.Text = "Update"; 2.114 - this.buttonUpdate.UseVisualStyleBackColor = true; 2.115 - this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); 2.116 - // 2.117 // tabPageAudio 2.118 // 2.119 this.tabPageAudio.Controls.Add(this.labelDefaultAudioDevice); 2.120 @@ -753,6 +699,97 @@ 2.121 this.toolTip.SetToolTip(this.trackBarMasterVolume, "Master Volume"); 2.122 this.trackBarMasterVolume.Scroll += new System.EventHandler(this.trackBarMasterVolume_Scroll); 2.123 // 2.124 + // tabPageInput 2.125 + // 2.126 + this.tabPageInput.Controls.Add(this.labelStartFileName); 2.127 + this.tabPageInput.Controls.Add(this.buttonSelectFile); 2.128 + this.tabPageInput.Location = new System.Drawing.Point(4, 22); 2.129 + this.tabPageInput.Name = "tabPageInput"; 2.130 + this.tabPageInput.Padding = new System.Windows.Forms.Padding(3); 2.131 + this.tabPageInput.Size = new System.Drawing.Size(592, 242); 2.132 + this.tabPageInput.TabIndex = 6; 2.133 + this.tabPageInput.Text = "Input"; 2.134 + this.tabPageInput.UseVisualStyleBackColor = true; 2.135 + // 2.136 + // labelStartFileName 2.137 + // 2.138 + this.labelStartFileName.AutoSize = true; 2.139 + this.labelStartFileName.Location = new System.Drawing.Point(37, 11); 2.140 + this.labelStartFileName.Name = "labelStartFileName"; 2.141 + this.labelStartFileName.Size = new System.Drawing.Size(33, 13); 2.142 + this.labelStartFileName.TabIndex = 1; 2.143 + this.labelStartFileName.Text = "None"; 2.144 + // 2.145 + // buttonSelectFile 2.146 + // 2.147 + this.buttonSelectFile.Location = new System.Drawing.Point(6, 6); 2.148 + this.buttonSelectFile.Name = "buttonSelectFile"; 2.149 + this.buttonSelectFile.Size = new System.Drawing.Size(25, 23); 2.150 + this.buttonSelectFile.TabIndex = 0; 2.151 + this.buttonSelectFile.Text = "..."; 2.152 + this.buttonSelectFile.UseVisualStyleBackColor = true; 2.153 + this.buttonSelectFile.Click += new System.EventHandler(this.buttonSelectFile_Click); 2.154 + // 2.155 + // tabPageApp 2.156 + // 2.157 + this.tabPageApp.Controls.Add(this.checkBoxStartMinimized); 2.158 + this.tabPageApp.Controls.Add(this.checkBoxMinimizeToTray); 2.159 + this.tabPageApp.Controls.Add(this.checkBoxAutoStart); 2.160 + this.tabPageApp.Controls.Add(this.buttonUpdate); 2.161 + this.tabPageApp.Location = new System.Drawing.Point(4, 22); 2.162 + this.tabPageApp.Name = "tabPageApp"; 2.163 + this.tabPageApp.Padding = new System.Windows.Forms.Padding(3); 2.164 + this.tabPageApp.Size = new System.Drawing.Size(592, 242); 2.165 + this.tabPageApp.TabIndex = 4; 2.166 + this.tabPageApp.Text = "Application"; 2.167 + this.tabPageApp.UseVisualStyleBackColor = true; 2.168 + // 2.169 + // checkBoxStartMinimized 2.170 + // 2.171 + this.checkBoxStartMinimized.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 2.172 + this.checkBoxStartMinimized.AutoSize = true; 2.173 + this.checkBoxStartMinimized.Location = new System.Drawing.Point(8, 144); 2.174 + this.checkBoxStartMinimized.Name = "checkBoxStartMinimized"; 2.175 + this.checkBoxStartMinimized.Size = new System.Drawing.Size(96, 17); 2.176 + this.checkBoxStartMinimized.TabIndex = 16; 2.177 + this.checkBoxStartMinimized.Text = "Start minimized"; 2.178 + this.checkBoxStartMinimized.UseVisualStyleBackColor = true; 2.179 + this.checkBoxStartMinimized.CheckedChanged += new System.EventHandler(this.checkBoxStartMinimized_CheckedChanged); 2.180 + // 2.181 + // checkBoxMinimizeToTray 2.182 + // 2.183 + this.checkBoxMinimizeToTray.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 2.184 + this.checkBoxMinimizeToTray.AutoSize = true; 2.185 + this.checkBoxMinimizeToTray.Location = new System.Drawing.Point(8, 167); 2.186 + this.checkBoxMinimizeToTray.Name = "checkBoxMinimizeToTray"; 2.187 + this.checkBoxMinimizeToTray.Size = new System.Drawing.Size(133, 17); 2.188 + this.checkBoxMinimizeToTray.TabIndex = 15; 2.189 + this.checkBoxMinimizeToTray.Text = "Minimize to system tray"; 2.190 + this.checkBoxMinimizeToTray.UseVisualStyleBackColor = true; 2.191 + this.checkBoxMinimizeToTray.CheckedChanged += new System.EventHandler(this.checkBoxMinimizeToTray_CheckedChanged); 2.192 + // 2.193 + // checkBoxAutoStart 2.194 + // 2.195 + this.checkBoxAutoStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 2.196 + this.checkBoxAutoStart.AutoSize = true; 2.197 + this.checkBoxAutoStart.Location = new System.Drawing.Point(8, 190); 2.198 + this.checkBoxAutoStart.Name = "checkBoxAutoStart"; 2.199 + this.checkBoxAutoStart.Size = new System.Drawing.Size(143, 17); 2.200 + this.checkBoxAutoStart.TabIndex = 14; 2.201 + this.checkBoxAutoStart.Text = "Run on Windows startup"; 2.202 + this.checkBoxAutoStart.UseVisualStyleBackColor = true; 2.203 + this.checkBoxAutoStart.CheckedChanged += new System.EventHandler(this.checkBoxAutoStart_CheckedChanged); 2.204 + // 2.205 + // buttonUpdate 2.206 + // 2.207 + this.buttonUpdate.Location = new System.Drawing.Point(6, 213); 2.208 + this.buttonUpdate.Name = "buttonUpdate"; 2.209 + this.buttonUpdate.Size = new System.Drawing.Size(75, 23); 2.210 + this.buttonUpdate.TabIndex = 0; 2.211 + this.buttonUpdate.Text = "Update"; 2.212 + this.buttonUpdate.UseVisualStyleBackColor = true; 2.213 + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); 2.214 + // 2.215 // labelFontWidth 2.216 // 2.217 this.labelFontWidth.AutoSize = true; 2.218 @@ -779,6 +816,10 @@ 2.219 this.pictureBoxDemo.TabIndex = 21; 2.220 this.pictureBoxDemo.TabStop = false; 2.221 // 2.222 + // openFileDialog 2.223 + // 2.224 + this.openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; 2.225 + // 2.226 // MainForm 2.227 // 2.228 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 2.229 @@ -811,11 +852,13 @@ 2.230 this.tabControl.ResumeLayout(false); 2.231 this.tabPageDesign.ResumeLayout(false); 2.232 this.tabPageDesign.PerformLayout(); 2.233 - this.tabPageApp.ResumeLayout(false); 2.234 - this.tabPageApp.PerformLayout(); 2.235 this.tabPageAudio.ResumeLayout(false); 2.236 this.tabPageAudio.PerformLayout(); 2.237 ((System.ComponentModel.ISupportInitialize)(this.trackBarMasterVolume)).EndInit(); 2.238 + this.tabPageInput.ResumeLayout(false); 2.239 + this.tabPageInput.PerformLayout(); 2.240 + this.tabPageApp.ResumeLayout(false); 2.241 + this.tabPageApp.PerformLayout(); 2.242 ((System.ComponentModel.ISupportInitialize)(this.pictureBoxDemo)).EndInit(); 2.243 this.ResumeLayout(false); 2.244 this.PerformLayout(); 2.245 @@ -884,6 +927,10 @@ 2.246 private System.Windows.Forms.CheckBox checkBoxMute; 2.247 private System.Windows.Forms.CheckBox checkBoxShowVolumeLabel; 2.248 private System.Windows.Forms.Label labelDefaultAudioDevice; 2.249 + private System.Windows.Forms.TabPage tabPageInput; 2.250 + private System.Windows.Forms.Button buttonSelectFile; 2.251 + private System.Windows.Forms.OpenFileDialog openFileDialog; 2.252 + private System.Windows.Forms.Label labelStartFileName; 2.253 } 2.254 } 2.255
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/Server/MainForm.Hid.cs Wed Mar 18 18:31:37 2015 +0100 3.3 @@ -0,0 +1,158 @@ 3.4 +using System; 3.5 +using System.IO; 3.6 +using System.Collections.Generic; 3.7 +using System.Linq; 3.8 +using System.Text; 3.9 +using System.Threading.Tasks; 3.10 +using System.Diagnostics; 3.11 +using System.Runtime.InteropServices; 3.12 +using System.Windows.Forms; 3.13 +// 3.14 +using Hid = SharpLib.Hid; 3.15 +using SharpLib.Win32; 3.16 + 3.17 +namespace SharpDisplayManager 3.18 +{ 3.19 + [System.ComponentModel.DesignerCategory("Code")] 3.20 + public class MainFormHid: Form 3.21 + { 3.22 + 3.23 + [DllImport("USER32.DLL")] 3.24 + public static extern bool SetForegroundWindow(IntPtr hWnd); 3.25 + 3.26 + 3.27 + public delegate void OnHidEventDelegate(object aSender, Hid.Event aHidEvent); 3.28 + 3.29 + /// <summary> 3.30 + /// Use notably to handle green start key from IR remote control 3.31 + /// </summary> 3.32 + private Hid.Handler iHidHandler; 3.33 + 3.34 + protected void RegisterHidDevices() 3.35 + { 3.36 + // Register the input device to receive the commands from the 3.37 + // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp 3.38 + // for the vendor defined usage page. 3.39 + 3.40 + RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5]; 3.41 + 3.42 + int i = 0; 3.43 + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl; 3.44 + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl; 3.45 + rid[i].dwFlags = Const.RIDEV_INPUTSINK; 3.46 + rid[i].hwndTarget = Handle; 3.47 + 3.48 + i++; 3.49 + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; 3.50 + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl; 3.51 + rid[i].dwFlags = Const.RIDEV_INPUTSINK; 3.52 + rid[i].hwndTarget = Handle; 3.53 + 3.54 + i++; 3.55 + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; 3.56 + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection; 3.57 + rid[i].dwFlags = Const.RIDEV_INPUTSINK; 3.58 + rid[i].hwndTarget = Handle; 3.59 + 3.60 + i++; 3.61 + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; 3.62 + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl; 3.63 + rid[i].dwFlags = Const.RIDEV_INPUTSINK; 3.64 + rid[i].hwndTarget = Handle; 3.65 + 3.66 + i++; 3.67 + rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; 3.68 + rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad; 3.69 + rid[i].dwFlags = Const.RIDEV_INPUTSINK; 3.70 + rid[i].hwndTarget = Handle; 3.71 + 3.72 + //i++; 3.73 + //rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; 3.74 + //rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard; 3.75 + //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; 3.76 + //rid[i].hwndTarget = Handle; 3.77 + 3.78 + //i++; 3.79 + //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls; 3.80 + //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse; 3.81 + //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; 3.82 + //rid[i].hwndTarget = aHWND; 3.83 + 3.84 + 3.85 + iHidHandler = new SharpLib.Hid.Handler(rid); 3.86 + if (!iHidHandler.IsRegistered) 3.87 + { 3.88 + Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString()); 3.89 + } 3.90 + iHidHandler.OnHidEvent += HandleHidEventThreadSafe; 3.91 + } 3.92 + 3.93 + public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) 3.94 + { 3.95 + if (aHidEvent.IsStray) 3.96 + { 3.97 + //Stray event just ignore it 3.98 + return; 3.99 + } 3.100 + 3.101 + if (this.InvokeRequired) 3.102 + { 3.103 + //Not in the proper thread, invoke ourselves 3.104 + OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); 3.105 + this.Invoke(d, new object[] { aSender, aHidEvent }); 3.106 + } 3.107 + else 3.108 + { 3.109 + //We are in the proper thread 3.110 + if (aHidEvent.Usages.Count > 0 3.111 + && aHidEvent.UsagePage == (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl 3.112 + && aHidEvent.Usages[0] == (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart) 3.113 + //&& aHidEvent.UsagePage == (ushort)Hid.UsagePage.Consumer 3.114 + //&& aHidEvent.Usages[0] == (ushort)Hid.Usage.ConsumerControl.ThinkPadFullscreenMagnifier) 3.115 + 3.116 + { 3.117 + //First check if the process we want to launch already exists 3.118 + string procName = Path.GetFileNameWithoutExtension(Properties.Settings.Default.StartFileName); 3.119 + Process[] existingProcesses = Process.GetProcessesByName(procName); 3.120 + if (existingProcesses == null || existingProcesses.Length==0) 3.121 + { 3.122 + // Process do not exists just try to launch it 3.123 + ProcessStartInfo start = new ProcessStartInfo(); 3.124 + // Enter in the command line arguments, everything you would enter after the executable name itself 3.125 + //start.Arguments = arguments; 3.126 + // Enter the executable to run, including the complete path 3.127 + start.FileName = Properties.Settings.Default.StartFileName; 3.128 + start.WindowStyle = ProcessWindowStyle.Normal; 3.129 + start.CreateNoWindow = true; 3.130 + start.UseShellExecute = true; 3.131 + // Run the external process & wait for it to finish 3.132 + Process proc = Process.Start(start); 3.133 + 3.134 + //SL: We could have used that too 3.135 + //Shell32.Shell shell = new Shell32.Shell(); 3.136 + //shell.ShellExecute(Properties.Settings.Default.StartFileName); 3.137 + } 3.138 + else 3.139 + { 3.140 + SetForegroundWindow(existingProcesses[0].MainWindowHandle); 3.141 + } 3.142 + } 3.143 + } 3.144 + } 3.145 + 3.146 + 3.147 + protected override void WndProc(ref Message message) 3.148 + { 3.149 + switch (message.Msg) 3.150 + { 3.151 + case Const.WM_INPUT: 3.152 + //Returning zero means we processed that message. 3.153 + message.Result = new IntPtr(0); 3.154 + iHidHandler.ProcessInput(ref message); 3.155 + break; 3.156 + } 3.157 + //Is that needed? Check the docs. 3.158 + base.WndProc(ref message); 3.159 + } 3.160 + } 3.161 +}
4.1 --- a/Server/MainForm.cs Tue Mar 17 20:12:00 2015 +0100 4.2 +++ b/Server/MainForm.cs Wed Mar 18 18:31:37 2015 +0100 4.3 @@ -63,7 +63,8 @@ 4.4 /// <summary> 4.5 /// Our Display manager main form 4.6 /// </summary> 4.7 - public partial class MainForm : Form, IMMNotificationClient 4.8 + [System.ComponentModel.DesignerCategory("Form")] 4.9 + public partial class MainForm : MainFormHid, IMMNotificationClient 4.10 { 4.11 DateTime LastTickTime; 4.12 Display iDisplay; 4.13 @@ -996,6 +997,7 @@ 4.14 checkBoxConnectOnStartup.Checked = Properties.Settings.Default.DisplayConnectOnStartup; 4.15 checkBoxMinimizeToTray.Checked = Properties.Settings.Default.MinimizeToTray; 4.16 checkBoxStartMinimized.Checked = Properties.Settings.Default.StartMinimized; 4.17 + labelStartFileName.Text = Properties.Settings.Default.StartFileName; 4.18 checkBoxReverseScreen.Checked = cds.ReverseScreen; 4.19 checkBoxInverseColors.Checked = cds.InverseColors; 4.20 checkBoxShowVolumeLabel.Checked = cds.ShowVolumeLabel; 4.21 @@ -2023,6 +2025,26 @@ 4.22 //We need to re-create our bitmap. 4.23 iCreateBitmap = true; 4.24 } 4.25 + 4.26 + /// <summary> 4.27 + /// 4.28 + /// </summary> 4.29 + /// <param name="sender"></param> 4.30 + /// <param name="e"></param> 4.31 + private void buttonSelectFile_Click(object sender, EventArgs e) 4.32 + { 4.33 + //openFileDialog1.InitialDirectory = "c:\\"; 4.34 + //openFileDialog.Filter = "EXE files (*.exe)|*.exe|All files (*.*)|*.*"; 4.35 + //openFileDialog.FilterIndex = 1; 4.36 + openFileDialog.RestoreDirectory = true; 4.37 + 4.38 + if (DlgBox.ShowDialog(openFileDialog) == DialogResult.OK) 4.39 + { 4.40 + labelStartFileName.Text = openFileDialog.FileName; 4.41 + Properties.Settings.Default.StartFileName = openFileDialog.FileName; 4.42 + Properties.Settings.Default.Save(); 4.43 + } 4.44 + } 4.45 } 4.46 4.47 /// <summary>
5.1 --- a/Server/MainForm.resx Tue Mar 17 20:12:00 2015 +0100 5.2 +++ b/Server/MainForm.resx Wed Mar 18 18:31:37 2015 +0100 5.3 @@ -129,6 +129,9 @@ 5.4 <metadata name="toolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 5.5 <value>315, 17</value> 5.6 </metadata> 5.7 + <metadata name="openFileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 5.8 + <value>405, 17</value> 5.9 + </metadata> 5.10 <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 5.11 <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> 5.12 <value>
6.1 --- a/Server/MainFormHid.cs Tue Mar 17 20:12:00 2015 +0100 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,140 +0,0 @@ 6.4 -using System; 6.5 -using System.Collections.Generic; 6.6 -using System.Linq; 6.7 -using System.Text; 6.8 -using System.Threading.Tasks; 6.9 -using System.Diagnostics; 6.10 -using System.Runtime.InteropServices; 6.11 -using System.Windows.Forms; 6.12 -// 6.13 -using Hid = SharpLib.Hid; 6.14 -using SharpLib.Win32; 6.15 - 6.16 -namespace SharpDisplayManager 6.17 -{ 6.18 - [System.ComponentModel.DesignerCategory("Code")] 6.19 - public partial class MainForm: Form 6.20 - { 6.21 - public delegate void OnHidEventDelegate(object aSender, Hid.Event aHidEvent); 6.22 - 6.23 - /// <summary> 6.24 - /// Use notably to handle green start key from IR remote control 6.25 - /// </summary> 6.26 - private Hid.Handler iHidHandler; 6.27 - 6.28 - void RegisterHidDevices() 6.29 - { 6.30 - // Register the input device to receive the commands from the 6.31 - // remote device. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwmt/html/remote_control.asp 6.32 - // for the vendor defined usage page. 6.33 - 6.34 - RAWINPUTDEVICE[] rid = new RAWINPUTDEVICE[5]; 6.35 - 6.36 - int i = 0; 6.37 - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.WindowsMediaCenterRemoteControl; 6.38 - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.WindowsMediaCenter.WindowsMediaCenterRemoteControl; 6.39 - rid[i].dwFlags = Const.RIDEV_INPUTSINK; 6.40 - rid[i].hwndTarget = Handle; 6.41 - 6.42 - i++; 6.43 - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; 6.44 - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.ConsumerControl; 6.45 - rid[i].dwFlags = Const.RIDEV_INPUTSINK; 6.46 - rid[i].hwndTarget = Handle; 6.47 - 6.48 - i++; 6.49 - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.Consumer; 6.50 - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.Consumer.Selection; 6.51 - rid[i].dwFlags = Const.RIDEV_INPUTSINK; 6.52 - rid[i].hwndTarget = Handle; 6.53 - 6.54 - i++; 6.55 - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; 6.56 - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.SystemControl; 6.57 - rid[i].dwFlags = Const.RIDEV_INPUTSINK; 6.58 - rid[i].hwndTarget = Handle; 6.59 - 6.60 - i++; 6.61 - rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; 6.62 - rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.GamePad; 6.63 - rid[i].dwFlags = Const.RIDEV_INPUTSINK; 6.64 - rid[i].hwndTarget = Handle; 6.65 - 6.66 - //i++; 6.67 - //rid[i].usUsagePage = (ushort)SharpLib.Hid.UsagePage.GenericDesktopControls; 6.68 - //rid[i].usUsage = (ushort)SharpLib.Hid.UsageCollection.GenericDesktop.Keyboard; 6.69 - //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; 6.70 - //rid[i].hwndTarget = Handle; 6.71 - 6.72 - //i++; 6.73 - //rid[i].usUsagePage = (ushort)Hid.UsagePage.GenericDesktopControls; 6.74 - //rid[i].usUsage = (ushort)Hid.UsageCollection.GenericDesktop.Mouse; 6.75 - //rid[i].dwFlags = Const.RIDEV_EXINPUTSINK; 6.76 - //rid[i].hwndTarget = aHWND; 6.77 - 6.78 - 6.79 - iHidHandler = new SharpLib.Hid.Handler(rid); 6.80 - if (!iHidHandler.IsRegistered) 6.81 - { 6.82 - Debug.WriteLine("Failed to register raw input devices: " + Marshal.GetLastWin32Error().ToString()); 6.83 - } 6.84 - iHidHandler.OnHidEvent += HandleHidEventThreadSafe; 6.85 - } 6.86 - 6.87 - public void HandleHidEventThreadSafe(object aSender, SharpLib.Hid.Event aHidEvent) 6.88 - { 6.89 - if (aHidEvent.IsStray) 6.90 - { 6.91 - //Stray event just ignore it 6.92 - return; 6.93 - } 6.94 - 6.95 - if (this.InvokeRequired) 6.96 - { 6.97 - //Not in the proper thread, invoke ourselves 6.98 - OnHidEventDelegate d = new OnHidEventDelegate(HandleHidEventThreadSafe); 6.99 - this.Invoke(d, new object[] { aSender, aHidEvent }); 6.100 - } 6.101 - else 6.102 - { 6.103 - //We are in the proper thread 6.104 - //listViewEvents.Items.Insert(0, aHidEvent.ToListViewItem()); 6.105 - //toolStripStatusLabelDevice.Text = aHidEvent.Device.FriendlyName; 6.106 - 6.107 - if (aHidEvent.Usages.Count > 0 6.108 - && aHidEvent.UsagePage == (ushort)Hid.UsagePage.WindowsMediaCenterRemoteControl 6.109 - && aHidEvent.Usages[0] == (ushort)Hid.Usage.WindowsMediaCenterRemoteControl.GreenStart) 6.110 - { 6.111 - //Hard coding it all for now 6.112 - // Prepare the process to run 6.113 - ProcessStartInfo start = new ProcessStartInfo(); 6.114 - // Enter in the command line arguments, everything you would enter after the executable name itself 6.115 - //start.Arguments = arguments; 6.116 - // Enter the executable to run, including the complete path 6.117 - start.FileName = "C:\\Program Files (x86)\\Team MediaPortal\\MediaPortal\\MediaPortal.exe"; 6.118 - // Do you want to show a console window? 6.119 - start.WindowStyle = ProcessWindowStyle.Hidden; 6.120 - start.CreateNoWindow = true; 6.121 - // Run the external process & wait for it to finish 6.122 - Process proc = Process.Start(start); 6.123 - } 6.124 - } 6.125 - } 6.126 - 6.127 - protected override void WndProc(ref Message message) 6.128 - { 6.129 - switch (message.Msg) 6.130 - { 6.131 - case Const.WM_INPUT: 6.132 - //Returning zero means we processed that message. 6.133 - message.Result = new IntPtr(0); 6.134 - iHidHandler.ProcessInput(ref message); 6.135 - break; 6.136 - } 6.137 - //Is that needed? Check the docs. 6.138 - base.WndProc(ref message); 6.139 - } 6.140 - 6.141 - 6.142 - } 6.143 -}
7.1 --- a/Server/Properties/Settings.Designer.cs Tue Mar 17 20:12:00 2015 +0100 7.2 +++ b/Server/Properties/Settings.Designer.cs Wed Mar 18 18:31:37 2015 +0100 7.3 @@ -12,7 +12,7 @@ 7.4 7.5 7.6 [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 7.7 - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 7.8 + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "12.0.0.0")] 7.9 internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 7.10 7.11 private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 7.12 @@ -93,5 +93,17 @@ 7.13 this["StartMinimized"] = value; 7.14 } 7.15 } 7.16 + 7.17 + [global::System.Configuration.UserScopedSettingAttribute()] 7.18 + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 7.19 + [global::System.Configuration.DefaultSettingValueAttribute("None")] 7.20 + public string StartFileName { 7.21 + get { 7.22 + return ((string)(this["StartFileName"])); 7.23 + } 7.24 + set { 7.25 + this["StartFileName"] = value; 7.26 + } 7.27 + } 7.28 } 7.29 }
8.1 --- a/Server/Properties/Settings.settings Tue Mar 17 20:12:00 2015 +0100 8.2 +++ b/Server/Properties/Settings.settings Wed Mar 18 18:31:37 2015 +0100 8.3 @@ -20,5 +20,8 @@ 8.4 <Setting Name="StartMinimized" Type="System.Boolean" Scope="User"> 8.5 <Value Profile="(Default)">False</Value> 8.6 </Setting> 8.7 + <Setting Name="StartFileName" Type="System.String" Scope="User"> 8.8 + <Value Profile="(Default)">None</Value> 8.9 + </Setting> 8.10 </Settings> 8.11 </SettingsFile> 8.12 \ No newline at end of file
9.1 --- a/Server/SharpDisplayManager.csproj Tue Mar 17 20:12:00 2015 +0100 9.2 +++ b/Server/SharpDisplayManager.csproj Wed Mar 18 18:31:37 2015 +0100 9.3 @@ -131,12 +131,16 @@ 9.4 </ItemGroup> 9.5 <ItemGroup> 9.6 <Compile Include="CbtHook.cs" /> 9.7 - <Compile Include="MainFormHid.cs" /> 9.8 + <Compile Include="MainForm.Hid.cs"> 9.9 + <DependentUpon>MainForm.cs</DependentUpon> 9.10 + </Compile> 9.11 <Compile Include="NetworkManager.cs" /> 9.12 <Compile Include="DialogBox.cs" /> 9.13 <Compile Include="Display.cs" /> 9.14 <Compile Include="DisplaySettings.cs" /> 9.15 - <Compile Include="MainForm.cs" /> 9.16 + <Compile Include="MainForm.cs"> 9.17 + <SubType>Form</SubType> 9.18 + </Compile> 9.19 <Compile Include="MainForm.Designer.cs"> 9.20 <DependentUpon>MainForm.cs</DependentUpon> 9.21 </Compile> 9.22 @@ -237,6 +241,15 @@ 9.23 <Isolated>False</Isolated> 9.24 <EmbedInteropTypes>True</EmbedInteropTypes> 9.25 </COMReference> 9.26 + <COMReference Include="Shell32"> 9.27 + <Guid>{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}</Guid> 9.28 + <VersionMajor>1</VersionMajor> 9.29 + <VersionMinor>0</VersionMinor> 9.30 + <Lcid>0</Lcid> 9.31 + <WrapperTool>tlbimp</WrapperTool> 9.32 + <Isolated>False</Isolated> 9.33 + <EmbedInteropTypes>True</EmbedInteropTypes> 9.34 + </COMReference> 9.35 </ItemGroup> 9.36 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 9.37 <!-- To modify your build process, add your task inside one of the targets below and uncomment it.