From: <an...@us...> - 2007-08-03 16:49:09
|
Revision: 788 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=788&view=rev Author: and-81 Date: 2007-08-03 09:49:07 -0700 (Fri, 03 Aug 2007) Log Message: ----------- Modified Paths: -------------- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs trunk/plugins/IR Server Suite/Applications/Translator/ButtonMapping.cs trunk/plugins/IR Server Suite/Applications/Translator/Configuration.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.Designer.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs trunk/plugins/IR Server Suite/Applications/Translator/Forms/MainForm.cs trunk/plugins/IR Server Suite/Applications/Translator/Program.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/KeysCommand.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/MessageCommand.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/WindowList.cs trunk/plugins/IR Server Suite/Common/IrssUtils/IrssUtils.csproj trunk/plugins/IR Server Suite/Common/IrssUtils/Win32.cs trunk/plugins/IR Server Suite/IR Server Plugins/MCE Replacement Transceiver/MceIrApi.cs trunk/plugins/IR Server Suite/IR Server Plugins/MCE Replacement Transceiver/MceReplacementTransceiver.cs trunk/plugins/IR Server Suite/IR Server Plugins/MCE Replacement Transceiver/Properties/AssemblyInfo.cs trunk/plugins/IR Server Suite/IR Server Plugins/USB-UIRT Transceiver/UirtTransceiver.cs Added Paths: ----------- trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.Designer.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.cs trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.resx Removed Paths: ------------- trunk/plugins/IR Server Suite/IR Server Plugins/Microsoft MCE Transceiver/Program.cs Modified: trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/IR Server/IRServer.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -85,8 +85,11 @@ // Setup taskbar icon _notifyIcon = new NotifyIcon(); _notifyIcon.ContextMenuStrip = new ContextMenuStrip(); - _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem("&Setup", null, new EventHandler(ClickSetup))); - _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripMenuItem("&Quit", null, new EventHandler(ClickQuit))); + + _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripLabel("IR Server")); + _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); + _notifyIcon.ContextMenuStrip.Items.Add("&Setup", null, new EventHandler(ClickSetup)); + _notifyIcon.ContextMenuStrip.Items.Add("&Quit", null, new EventHandler(ClickQuit)); _notifyIcon.Icon = Properties.Resources.Icon16; _notifyIcon.Text = "IR Server"; } Modified: trunk/plugins/IR Server Suite/Applications/Translator/ButtonMapping.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/ButtonMapping.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/Translator/ButtonMapping.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -5,6 +5,9 @@ namespace Translator { + /// <summary> + /// Stores the relevant information for mapping a remote button to a command. + /// </summary> public class ButtonMapping { @@ -18,6 +21,9 @@ #region Properties + /// <summary> + /// Remote button key code. + /// </summary> [XmlAttribute] public string KeyCode { @@ -25,6 +31,9 @@ set { _keyCode = value; } } + /// <summary> + /// Remote button description. + /// </summary> [XmlAttribute] public string Description { @@ -32,6 +41,9 @@ set { _description = value; } } + /// <summary> + /// Command to execute for the remote button. + /// </summary> [XmlAttribute] public string Command { Modified: trunk/plugins/IR Server Suite/Applications/Translator/Configuration.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Configuration.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/Translator/Configuration.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -84,7 +84,7 @@ #endregion Constructors - #region Methods + #region Static Methods /// <summary> /// Save the supplied configuration to file. @@ -129,7 +129,7 @@ } } - #endregion Methods + #endregion Static Methods } Modified: trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.Designer.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.Designer.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.Designer.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -173,6 +173,9 @@ this.buttonCancel = new System.Windows.Forms.Button(); this.buttonOK = new System.Windows.Forms.Button(); this.toolTips = new System.Windows.Forms.ToolTip(this.components); + this.tabPageMisc = new System.Windows.Forms.TabPage(); + this.labelMiscCommand = new System.Windows.Forms.Label(); + this.comboBoxMiscCommand = new System.Windows.Forms.ComboBox(); this.groupBoxButton.SuspendLayout(); this.groupBoxSet.SuspendLayout(); this.tabControl.SuspendLayout(); @@ -196,6 +199,7 @@ this.groupBoxMouseClick.SuspendLayout(); this.groupBoxMouseMove.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMouseMove)).BeginInit(); + this.tabPageMisc.SuspendLayout(); this.SuspendLayout(); // // groupBoxButton @@ -307,6 +311,7 @@ this.tabControl.Controls.Add(this.tabPageMessage); this.tabControl.Controls.Add(this.tabPageKeystrokes); this.tabControl.Controls.Add(this.tabPageMouse); + this.tabControl.Controls.Add(this.tabPageMisc); this.tabControl.Location = new System.Drawing.Point(8, 24); this.tabControl.Name = "tabControl"; this.tabControl.SelectedIndex = 0; @@ -1671,6 +1676,36 @@ this.buttonOK.UseVisualStyleBackColor = true; this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); // + // tabPageMisc + // + this.tabPageMisc.Controls.Add(this.labelMiscCommand); + this.tabPageMisc.Controls.Add(this.comboBoxMiscCommand); + this.tabPageMisc.Location = new System.Drawing.Point(4, 22); + this.tabPageMisc.Name = "tabPageMisc"; + this.tabPageMisc.Padding = new System.Windows.Forms.Padding(3); + this.tabPageMisc.Size = new System.Drawing.Size(432, 206); + this.tabPageMisc.TabIndex = 7; + this.tabPageMisc.Text = "Misc"; + this.tabPageMisc.UseVisualStyleBackColor = true; + // + // labelMiscCommand + // + this.labelMiscCommand.Location = new System.Drawing.Point(8, 16); + this.labelMiscCommand.Name = "labelMiscCommand"; + this.labelMiscCommand.Size = new System.Drawing.Size(88, 21); + this.labelMiscCommand.TabIndex = 0; + this.labelMiscCommand.Text = "Command:"; + this.labelMiscCommand.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; + // + // comboBoxMiscCommand + // + this.comboBoxMiscCommand.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxMiscCommand.FormattingEnabled = true; + this.comboBoxMiscCommand.Location = new System.Drawing.Point(96, 16); + this.comboBoxMiscCommand.Name = "comboBoxMiscCommand"; + this.comboBoxMiscCommand.Size = new System.Drawing.Size(328, 21); + this.comboBoxMiscCommand.TabIndex = 1; + // // ButtonMappingForm // this.AcceptButton = this.buttonOK; @@ -1719,6 +1754,7 @@ this.groupBoxMouseClick.ResumeLayout(false); this.groupBoxMouseMove.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownMouseMove)).EndInit(); + this.tabPageMisc.ResumeLayout(false); this.ResumeLayout(false); } @@ -1868,6 +1904,9 @@ private System.Windows.Forms.ToolStripMenuItem altToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem controlToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem shiftToolStripMenuItem; + private System.Windows.Forms.TabPage tabPageMisc; + private System.Windows.Forms.Label labelMiscCommand; + private System.Windows.Forms.ComboBox comboBoxMiscCommand; } } \ No newline at end of file Modified: trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/Translator/Forms/ButtonMappingForm.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -49,9 +49,9 @@ { InitializeComponent(); - _keyCode = keyCode; - _description = description; - _command = command; + _keyCode = keyCode; + _description = description; + _command = command; } #endregion Constructors @@ -130,12 +130,27 @@ comboBoxWindowStyle.Items.AddRange(Enum.GetNames(typeof(ProcessWindowStyle))); comboBoxWindowStyle.SelectedIndex = 0; + // Setup Misc tab + comboBoxMiscCommand.Items.Clear(); + comboBoxMiscCommand.Items.Add(Common.UITextEject); + comboBoxMiscCommand.Items.Add(Common.UITextStandby); + comboBoxMiscCommand.Items.Add(Common.UITextHibernate); + comboBoxMiscCommand.Items.Add(Common.UITextReboot); + comboBoxMiscCommand.Items.Add(Common.UITextShutdown); + + if (!String.IsNullOrEmpty(_command)) { + string prefix = _command; + string suffix = String.Empty; + int find = _command.IndexOf(": "); - string prefix = _command.Substring(0, find + 2); - string suffix = _command.Substring(find + 2); + if (find != -1) + { + prefix = _command.Substring(0, find + 2); + suffix = _command.Substring(find + 2); + } switch (prefix) { @@ -242,6 +257,25 @@ } break; } + + default: + { + tabControl.SelectTab(tabPageMisc); + switch (_command) + { + case Common.CmdPrefixHibernate: + comboBoxMiscCommand.SelectedItem = Common.UITextHibernate; + break; + + default: + if (prefix.Equals(Common.CmdPrefixEject, StringComparison.InvariantCultureIgnoreCase)) + { + comboBoxMiscCommand.SelectedItem = Common.UITextEject; + } + break; + } + break; + } } } @@ -393,6 +427,28 @@ textBoxCommand.Text = _command = newCommand.ToString(); break; } + + case "tabPageMisc": + { + string newCommand = comboBoxMiscCommand.SelectedItem as string; + + switch (newCommand) + { + case Common.UITextEject: + textBoxCommand.Text = _command = Common.CmdPrefixEject; + break; + + case Common.UITextHibernate: + textBoxCommand.Text = _command = Common.CmdPrefixHibernate; + break; + + + } + + + + break; + } } } Modified: trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/Translator/Forms/MacroEditor.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -46,6 +46,8 @@ comboBoxCommands.Items.Add(Common.UITextWindowMsg); comboBoxCommands.Items.Add(Common.UITextTcpMsg); comboBoxCommands.Items.Add(Common.UITextKeys); + comboBoxCommands.Items.Add(Common.UITextEject); + //TODO: Add Shutdown and Reboot comboBoxCommands.Items.Add(Common.UITextStandby); comboBoxCommands.Items.Add(Common.UITextHibernate); @@ -105,6 +107,11 @@ writer.WriteAttributeString("command", Common.XmlTagKeys); writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixKeys.Length)); } + else if (item.StartsWith(Common.CmdPrefixEject)) + { + writer.WriteAttributeString("command", Common.XmlTagEject); + writer.WriteAttributeString("cmdproperty", item.Substring(Common.CmdPrefixEject.Length)); + } else if (item.StartsWith(Common.CmdPrefixStandby)) { writer.WriteAttributeString("command", Common.XmlTagStandby); @@ -172,6 +179,10 @@ listBoxMacro.Items.Add(Common.CmdPrefixKeys + commandProperty); break; + case Common.XmlTagEject: + listBoxMacro.Items.Add(Common.CmdPrefixEject + commandProperty); + break; + case Common.XmlTagStandby: listBoxMacro.Items.Add(Common.CmdPrefixStandby); break; @@ -250,6 +261,14 @@ listBoxMacro.Items.Add(Common.CmdPrefixKeys + keysCommand.CommandString); } + else if (selected == Common.UITextEject) + { + EjectCommand ejectCommand = new EjectCommand(); + if (ejectCommand.ShowDialog(this) == DialogResult.Cancel) + return; + + listBoxMacro.Items.Add(Common.CmdPrefixEject + ejectCommand.CommandString); + } else if (selected == Common.UITextStandby) { listBoxMacro.Items.Add(Common.CmdPrefixStandby); @@ -422,6 +441,17 @@ listBoxMacro.Items.Insert(index, Common.CmdPrefixKeys + keysCommand.CommandString); listBoxMacro.SelectedIndex = index; } + else if (selected.StartsWith(Common.CmdPrefixEject)) + { + EjectCommand ejectCommand = new EjectCommand(selected.Substring(Common.CmdPrefixEject.Length)); + if (ejectCommand.ShowDialog(this) == DialogResult.Cancel) + return; + + int index = listBoxMacro.SelectedIndex; + listBoxMacro.Items.RemoveAt(index); + listBoxMacro.Items.Insert(index, Common.CmdPrefixEject + ejectCommand.CommandString); + listBoxMacro.SelectedIndex = index; + } else if (selected.StartsWith(Common.CmdPrefixBlast)) { string[] commands = Common.SplitBlastCommand(selected.Substring(Common.CmdPrefixBlast.Length)); Modified: trunk/plugins/IR Server Suite/Applications/Translator/Forms/MainForm.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Forms/MainForm.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/Translator/Forms/MainForm.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -194,6 +194,8 @@ string[] macroList = Program.GetMacroList(false); if (macroList != null && macroList.Length > 0) listBoxMacro.Items.AddRange(macroList); + + Program.UpdateNotifyMenu(); } List<ButtonMapping> GetCurrentSettings() @@ -307,6 +309,35 @@ Configuration.Save(Program.Config, Program.ConfigFile); } + protected override void WndProc(ref Message m) + { + try + { + if (m.Msg == (int)Win32.WindowsMessage.WM_COPYDATA) + { + IrssLog.Info("Received WM_COPYDATA message"); + + Win32.COPYDATASTRUCT dataStructure = (Win32.COPYDATASTRUCT)m.GetLParam(typeof(Win32.COPYDATASTRUCT)); + + if (dataStructure.dwData != 24) + return; + + byte[] dataBytes = new byte[dataStructure.cbData]; + IntPtr lpData = new IntPtr(dataStructure.lpData); + System.Runtime.InteropServices.Marshal.Copy(lpData, dataBytes, 0, dataStructure.cbData); + string strData = Encoding.Default.GetString(dataBytes); + + Program.ProcessCommand(strData); + } + } + catch (Exception ex) + { + IrssLog.Error(ex.ToString()); + } + + base.WndProc(ref m); + } + #region Controls private void listViewButtons_DoubleClick(object sender, EventArgs e) Modified: trunk/plugins/IR Server Suite/Applications/Translator/Program.cs =================================================================== --- trunk/plugins/IR Server Suite/Applications/Translator/Program.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Applications/Translator/Program.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.IO.Ports; @@ -111,6 +112,10 @@ static TransceiverInfo _transceiverInfo = new TransceiverInfo(); + //static Thread _focusWatcher; + static IntPtr _ownWindowHandle = IntPtr.Zero; + static IntPtr _currentForegroundWindow = IntPtr.Zero; + #endregion Variables #region Properties @@ -143,9 +148,49 @@ #region Main + /// <summary> + /// The main entry point for the application. + /// </summary> [STAThread] - static void Main() + static void Main(string[] args) { + if (args.Length > 0) + { + for (int index = 0; index < args.Length; index++) + { + switch (args[index].ToLowerInvariant()) + { + case "-macro": + SendCopyDataMessage("Translator", Common.CmdPrefixMacro + args[++index]); + continue; + + case "-eject": + SendCopyDataMessage("Translator", Common.CmdPrefixEject + args[++index]); + continue; + + case "-shutdown": + SendCopyDataMessage("Translator", Common.CmdPrefixShutdown); + continue; + + case "-reboot": + SendCopyDataMessage("Translator", Common.CmdPrefixReboot); + continue; + + case "-standby": + SendCopyDataMessage("Translator", Common.CmdPrefixStandby); + continue; + + case "-hibernate": + SendCopyDataMessage("Translator", Common.CmdPrefixHibernate); + continue; + + //TODO: Add more command line options. + } + } + + return; + } + // Check for multiple instances. if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length != 1) return; @@ -184,7 +229,16 @@ // Setup main form ... _mainForm = new MainForm(); + _ownWindowHandle = _mainForm.Handle; + // Start the window focus watcher thread + /* + _focusWatcher = new Thread(new ThreadStart(FocusWatcherThread)); + _focusWatcher.Name = "Translator - Focus watcher"; + _focusWatcher.IsBackground = true; + _focusWatcher.Start(); + */ + // Start server communications ... if (StartComms()) { @@ -204,13 +258,89 @@ StopComms(); + //if (_focusWatcher.IsAlive) + //_focusWatcher.Abort(); + IrssLog.Close(); } + static void FocusWatcherThread() + { + try + { + while (true) + { + UpdateForegroundWindow(); + Thread.Sleep(2000); + } + } + catch + { + } + } + + static void UpdateForegroundWindow() + { + try + { + IntPtr hWnd = Win32.GetForegroundWindow(); + + if (hWnd == IntPtr.Zero) + return; + + if (hWnd == _mainForm.Handle) + return; +/* + string windowTitle = Win32.GetWindowTitle(hWnd); + if (windowTitle.StartsWith("Translator", StringComparison.InvariantCultureIgnoreCase)) + return; + + int procID; + Win32.GetWindowThreadProcessId(hWnd, out procID); + Process proc = Process.GetProcessById(procID); + if (proc.MainModule.ModuleName.Equals("Translator.exe", StringComparison.InvariantCultureIgnoreCase)) + return; + */ + _currentForegroundWindow = hWnd; + } + catch + { + } + } + #endregion Main #region Implementation + static void ShowTranslatorMenu() + { + UpdateForegroundWindow(); + _notifyIcon.ContextMenuStrip.Show(Screen.PrimaryScreen.Bounds.Width / 4, Screen.PrimaryScreen.Bounds.Height / 4); + //_notifyIcon.ContextMenuStrip.Focus(); + } + + static void SendCopyDataMessage(string targetWindow, string data) + { + Win32.COPYDATASTRUCT copyData; + + copyData.dwData = 24; + copyData.lpData = Win32.VarPtr(data).ToInt32(); + copyData.cbData = data.Length; + + IntPtr windowHandle = Win32.FindWindow(null, targetWindow); + if (windowHandle != IntPtr.Zero) + { + IntPtr result; + Win32.SendMessageTimeout(windowHandle, (int)Win32.WindowsMessage.WM_COPYDATA, IntPtr.Zero, Win32.VarPtr(copyData), Win32.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out result); + + if (result == IntPtr.Zero) + { + int lastError = Marshal.GetLastWin32Error(); + throw new Win32Exception(lastError); + } + } + } + static void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) { switch (e.Mode) @@ -243,6 +373,9 @@ { _notifyIcon.ContextMenuStrip.Items.Clear(); + _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripLabel("Translator")); + _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); + if (Config.Programs.Count > 0) { ToolStripMenuItem launch = new ToolStripMenuItem("&Launch"); @@ -277,6 +410,7 @@ _notifyIcon.ContextMenuStrip.Items.Add(macros); } + /**/ ToolStripMenuItem actions = new ToolStripMenuItem("&Actions"); actions.DropDownItems.Add("Next Window", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("Last Window", null, new EventHandler(ClickAction)); @@ -285,25 +419,54 @@ actions.DropDownItems.Add("Minimize Window", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("Restore Window", null, new EventHandler(ClickAction)); + actions.DropDownItems.Add(new ToolStripSeparator()); + actions.DropDownItems.Add("System Standby", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("System Hibernate", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("System Reboot", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("System Logoff", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("System Shutdown", null, new EventHandler(ClickAction)); + + actions.DropDownItems.Add(new ToolStripSeparator()); actions.DropDownItems.Add("Volume Up", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("Volume Down", null, new EventHandler(ClickAction)); actions.DropDownItems.Add("Volume Mute", null, new EventHandler(ClickAction)); + actions.DropDownItems.Add(new ToolStripSeparator()); + ToolStripMenuItem ejectMenu = new ToolStripMenuItem("Eject"); + DriveInfo[] drives = DriveInfo.GetDrives(); + foreach (DriveInfo drive in drives) + if (drive.DriveType == DriveType.CDRom) + ejectMenu.DropDownItems.Add(drive.Name, null, new EventHandler(ClickEjectAction)); + actions.DropDownItems.Add(ejectMenu); + _notifyIcon.ContextMenuStrip.Items.Add(actions); + /**/ _notifyIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator()); - _notifyIcon.ContextMenuStrip.Items.Add("&Setup", null, new EventHandler(ClickSetup)); _notifyIcon.ContextMenuStrip.Items.Add("&Quit", null, new EventHandler(ClickQuit)); } + /**/ + static bool SendMessageToWindow(IntPtr hWnd, Win32.WindowsMessage msg, int wParam, int lParam) + { + IntPtr result; + Win32.SendMessageTimeout(hWnd, (int)msg, new IntPtr(wParam), new IntPtr(lParam), Win32.SendMessageTimeoutFlags.SMTO_ABORTIFHUNG, 1000, out result); + + if (result == IntPtr.Zero) + { + int lastError = Marshal.GetLastWin32Error(); + if (lastError != 0) + throw new Win32Exception(lastError); + } + + return true; + } + /**/ + static void ClickProgram(object sender, EventArgs e) { IrssLog.Info("Click Launch Program"); @@ -371,7 +534,6 @@ MessageBox.Show(ex.Message, "Macro failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - static void ClickAction(object sender, EventArgs e) { IrssLog.Info("Click Action"); @@ -385,50 +547,98 @@ switch (menuItem.Text) { case "Next Window": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_SYSCOMMAND, + (int)Win32.SysCommand.SC_NEXTWINDOW, + 0); break; case "Last Window": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_SYSCOMMAND, + (int)Win32.SysCommand.SC_PREVWINDOW, + 0); break; case "Close Window": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_SYSCOMMAND, + (int)Win32.SysCommand.SC_CLOSE, + 0); break; case "Maximize Window": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_SYSCOMMAND, + (int)Win32.SysCommand.SC_MAXIMIZE, + 0); break; case "Minimize Window": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_SYSCOMMAND, + (int)Win32.SysCommand.SC_MINIMIZE, + 0); break; case "Restore Window": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_SYSCOMMAND, + (int)Win32.SysCommand.SC_RESTORE, + 0); break; - case "System Standby": + Application.SetSuspendState(PowerState.Suspend, true, false); break; case "System Hibernate": + Application.SetSuspendState(PowerState.Hibernate, true, false); break; case "System Reboot": + Win32.ExitWindowsEx(Win32.ExitWindows.Reboot | Win32.ExitWindows.ForceIfHung, Win32.ShutdownReason.FlagUserDefined); break; case "System Logoff": + Win32.ExitWindowsEx(Win32.ExitWindows.LogOff | Win32.ExitWindows.ForceIfHung, Win32.ShutdownReason.FlagUserDefined); break; case "System Shutdown": + Win32.ExitWindowsEx(Win32.ExitWindows.ShutDown | Win32.ExitWindows.ForceIfHung, Win32.ShutdownReason.FlagUserDefined); break; case "Volume Up": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_APPCOMMAND, + (int)Win32.AppCommand.APPCOMMAND_VOLUME_UP, + 0); break; case "Volume Down": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_APPCOMMAND, + (int)Win32.AppCommand.APPCOMMAND_VOLUME_DOWN, + 0); break; case "Volume Mute": + SendMessageToWindow( + _currentForegroundWindow, + Win32.WindowsMessage.WM_APPCOMMAND, + (int)Win32.AppCommand.APPCOMMAND_VOLUME_MUTE, + 0); break; - default: throw new Exception("Unknown action: " + menuItem.Text); } @@ -440,6 +650,16 @@ } } + static void ClickEjectAction(object sender, EventArgs e) + { + IrssLog.Info("Click Eject Action"); + + ToolStripMenuItem menuItem = sender as ToolStripMenuItem; + if (menuItem == null) + return; + + CDRom.Open(menuItem.Text); + } static void ClickSetup(object sender, EventArgs e) { @@ -978,7 +1198,10 @@ { ProcessCommand(mappedEvent.Command); } - catch (Exception ex) { IrssLog.Error(ex.ToString()); } + catch (Exception ex) + { + IrssLog.Error(ex.ToString()); + } } } } @@ -1054,6 +1277,12 @@ break; } + case Common.XmlTagEject: + { + Common.ProcessEjectCommand(commandProperty); + break; + } + case Common.XmlTagStandby: { Application.SetSuspendState(PowerState.Suspend, true, false); @@ -1181,6 +1410,11 @@ string keyCommand = command.Substring(Common.CmdPrefixKeys.Length); Common.ProcessKeyCommand(keyCommand); } + else if (command.StartsWith(Common.CmdPrefixEject)) // Eject Command + { + string ejectCommand = command.Substring(Common.CmdPrefixEject.Length); + Common.ProcessEjectCommand(ejectCommand); + } else if (command.StartsWith(Common.CmdPrefixMouse)) // Mouse Command { string mouseCommand = command.Substring(Common.CmdPrefixMouse.Length); Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Common.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -122,6 +122,8 @@ public const string CmdPrefixMouse = "Mouse: "; + public const string CmdPrefixEject = "Eject: "; + #endregion Command Prefixes #region XML Tags @@ -148,6 +150,8 @@ public const string XmlTagMouse = "MOUSE"; + public const string XmlTagEject = "EJECT"; + #endregion XML Tags #region User Interface Text @@ -173,6 +177,8 @@ public const string UITextMouse = "Mouse Command"; + public const string UITextEject = "Eject CD"; + #endregion User Interface Text #region Mouse Commands @@ -481,6 +487,16 @@ } } + /// <summary> + /// Given a CD-ROM drive letter this method will eject the CD tray. + /// </summary> + /// <param name="command">The drive letter of the CD-ROM drive to eject the tray on.</param> + public static void ProcessEjectCommand(string command) + { + if (CDRom.IsCDRom(command)) + CDRom.Open(command); + } + #endregion Command Execution #region Misc Added: trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.Designer.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.Designer.cs (rev 0) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.Designer.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -0,0 +1,110 @@ +namespace IrssUtils.Forms +{ + + partial class EjectCommand + { + + /// <summary> + /// Required designer variable. + /// </summary> + private System.ComponentModel.IContainer components = null; + + /// <summary> + /// Clean up any resources being used. + /// </summary> + /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// <summary> + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// </summary> + private void InitializeComponent() + { + this.buttonCancel = new System.Windows.Forms.Button(); + this.buttonOK = new System.Windows.Forms.Button(); + this.labelDrive = new System.Windows.Forms.Label(); + this.comboBoxDrive = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; + this.buttonCancel.Location = new System.Drawing.Point(80, 56); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(64, 24); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // buttonOK + // + this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOK.Location = new System.Drawing.Point(8, 56); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(64, 24); + this.buttonOK.TabIndex = 2; + this.buttonOK.Text = "OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); + // + // labelDrive + // + this.labelDrive.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.labelDrive.Location = new System.Drawing.Point(8, 8); + this.labelDrive.Name = "labelDrive"; + this.labelDrive.Size = new System.Drawing.Size(136, 16); + this.labelDrive.TabIndex = 0; + this.labelDrive.Text = "Select drive to eject:"; + // + // comboBoxDrive + // + this.comboBoxDrive.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.comboBoxDrive.FormattingEnabled = true; + this.comboBoxDrive.Location = new System.Drawing.Point(8, 24); + this.comboBoxDrive.Name = "comboBoxDrive"; + this.comboBoxDrive.Size = new System.Drawing.Size(136, 21); + this.comboBoxDrive.TabIndex = 1; + // + // EjectCommand + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(152, 89); + this.Controls.Add(this.comboBoxDrive); + this.Controls.Add(this.labelDrive); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOK); + this.MaximizeBox = false; + this.MinimizeBox = false; + this.MinimumSize = new System.Drawing.Size(160, 116); + this.Name = "EjectCommand"; + this.ShowIcon = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Eject Command"; + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Button buttonCancel; + private System.Windows.Forms.Button buttonOK; + private System.Windows.Forms.Label labelDrive; + private System.Windows.Forms.ComboBox comboBoxDrive; + } + +} Added: trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.cs (rev 0) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Text; +using System.Windows.Forms; + +namespace IrssUtils.Forms +{ + + public partial class EjectCommand : Form + { + + #region Properties + + public string CommandString + { + get + { + return comboBoxDrive.Text; + } + } + + #endregion Properties + + #region Constructors + + public EjectCommand() : this(null) { } + public EjectCommand(string command) + { + InitializeComponent(); + + DriveInfo[] drives = DriveInfo.GetDrives(); + foreach (DriveInfo drive in drives) + { + if (drive.DriveType == DriveType.CDRom) + { + comboBoxDrive.Items.Add(drive.Name); + if (drive.Name == command) + comboBoxDrive.SelectedItem = drive.Name; + } + } + + } + + #endregion + + #region Buttons + + private void buttonOK_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + this.DialogResult = DialogResult.Cancel; + this.Close(); + } + + #endregion Buttons + + } + +} Added: trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.resx =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.resx (rev 0) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/EjectCommand.resx 2007-08-03 16:49:07 UTC (rev 788) @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<root> + <!-- + Microsoft ResX Schema + + Version 2.0 + + The primary goals of this format is to allow a simple XML format + that is mostly human readable. The generation and parsing of the + various data types are done through the TypeConverter classes + associated with the data types. + + Example: + + ... ado.net/XML headers & schema ... + <resheader name="resmimetype">text/microsoft-resx</resheader> + <resheader name="version">2.0</resheader> + <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> + <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> + <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data> + <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> + <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> + <value>[base64 mime encoded serialized .NET Framework object]</value> + </data> + <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> + <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value> + <comment>This is a comment</comment> + </data> + + There are any number of "resheader" rows that contain simple + name/value pairs. + + Each data row contains a name, and value. The row also contains a + type or mimetype. Type corresponds to a .NET class that support + text/value conversion through the TypeConverter architecture. + Classes that don't support this are serialized and stored with the + mimetype set. + + The mimetype is used for serialized objects, and tells the + ResXResourceReader how to depersist the object. This is currently not + extensible. For a given mimetype the value must be set accordingly: + + Note - application/x-microsoft.net.object.binary.base64 is the format + that the ResXResourceWriter will generate, however the reader can + read any of the formats listed below. + + mimetype: application/x-microsoft.net.object.binary.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.soap.base64 + value : The object must be serialized with + : System.Runtime.Serialization.Formatters.Soap.SoapFormatter + : and then encoded with base64 encoding. + + mimetype: application/x-microsoft.net.object.bytearray.base64 + value : The object must be serialized into a byte array + : using a System.ComponentModel.TypeConverter + : and then encoded with base64 encoding. + --> + <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> + <xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> + <xsd:element name="root" msdata:IsDataSet="true"> + <xsd:complexType> + <xsd:choice maxOccurs="unbounded"> + <xsd:element name="metadata"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" /> + </xsd:sequence> + <xsd:attribute name="name" use="required" type="xsd:string" /> + <xsd:attribute name="type" type="xsd:string" /> + <xsd:attribute name="mimetype" type="xsd:string" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="assembly"> + <xsd:complexType> + <xsd:attribute name="alias" type="xsd:string" /> + <xsd:attribute name="name" type="xsd:string" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="data"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" /> + <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> + <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> + <xsd:attribute ref="xml:space" /> + </xsd:complexType> + </xsd:element> + <xsd:element name="resheader"> + <xsd:complexType> + <xsd:sequence> + <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> + </xsd:sequence> + <xsd:attribute name="name" type="xsd:string" use="required" /> + </xsd:complexType> + </xsd:element> + </xsd:choice> + </xsd:complexType> + </xsd:element> + </xsd:schema> + <resheader name="resmimetype"> + <value>text/microsoft-resx</value> + </resheader> + <resheader name="version"> + <value>2.0</value> + </resheader> + <resheader name="reader"> + <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> + <resheader name="writer"> + <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> + </resheader> +</root> \ No newline at end of file Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/KeysCommand.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/KeysCommand.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/KeysCommand.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -31,7 +31,7 @@ { InitializeComponent(); - if (command != null) + if (!String.IsNullOrEmpty(command)) textBoxKeystrokes.Text = command; } Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/MessageCommand.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/MessageCommand.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/MessageCommand.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -52,7 +52,7 @@ #region Constructors - public MessageCommand() : this(new string[] { "active", String.Empty, Win32.WM_USER.ToString(), "0", "0" }) { } + public MessageCommand() : this(new string[] { "active", String.Empty, ((int)Win32.WindowsMessage.WM_USER).ToString(), "0", "0" }) { } public MessageCommand(string[] commands) { InitializeComponent(); @@ -104,7 +104,9 @@ } else if (radioButtonWindowTitle.Checked) { - // TODO: Locate Window + WindowList windowList = new WindowList(); + if (windowList.ShowDialog(this) == DialogResult.OK) + textBoxMsgTarget.Text = windowList.SelectedWindowTitle; } } @@ -122,11 +124,11 @@ private void wMAPPToolStripMenuItem_Click(object sender, EventArgs e) { - numericUpDownMsg.Value = new decimal(Win32.WM_APP); + numericUpDownMsg.Value = new decimal((int)Win32.WindowsMessage.WM_APP); } private void wMUSERToolStripMenuItem_Click(object sender, EventArgs e) { - numericUpDownMsg.Value = new decimal(Win32.WM_USER); + numericUpDownMsg.Value = new decimal((int)Win32.WindowsMessage.WM_USER); } private void radioButtonActiveWindow_CheckedChanged(object sender, EventArgs e) Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/WindowList.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/WindowList.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Forms/WindowList.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -13,18 +13,6 @@ public partial class WindowList : Form { - #region Interop - - public delegate bool EnumWindowsProc(int hWnd, int lParam); - - [DllImport("user32.dll")] - private static extern int GetWindowText(int hWnd, StringBuilder title, int size); - - [DllImport("user32.dll")] - private static extern int EnumWindows(EnumWindowsProc ewp, int lParam); - - #endregion Interop - #region Properties public string SelectedWindowTitle @@ -47,18 +35,17 @@ void PopulateList() { - EnumWindowsProc ewp = new EnumWindowsProc(AddWindow); + Win32.EnumWindowsProc ewp = new Win32.EnumWindowsProc(AddWindow); - EnumWindows(ewp, 0); + Win32.EnumWindows(ewp, 0); } - bool AddWindow(int hWnd, int lParam) + bool AddWindow(IntPtr hWnd, int lParam) { - StringBuilder title = new StringBuilder(256); - GetWindowText(hWnd, title, 256); + string title = Win32.GetWindowTitle(hWnd); - if (title.Length != 0) - listBoxWindows.Items.Add(title.ToString()); + if (!String.IsNullOrEmpty(title)) + listBoxWindows.Items.Add(title); return true; } Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/IrssUtils.csproj =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/IrssUtils.csproj 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/IrssUtils.csproj 2007-08-03 16:49:07 UTC (rev 788) @@ -42,6 +42,12 @@ <ItemGroup> <Compile Include="CDRom.cs" /> <Compile Include="Common.cs" /> + <Compile Include="Forms\EjectCommand.cs"> + <SubType>Form</SubType> + </Compile> + <Compile Include="Forms\EjectCommand.Designer.cs"> + <DependentUpon>EjectCommand.cs</DependentUpon> + </Compile> <Compile Include="Forms\MouseCommand.cs"> <SubType>Form</SubType> </Compile> @@ -117,6 +123,10 @@ <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <ItemGroup> + <EmbeddedResource Include="Forms\EjectCommand.resx"> + <DependentUpon>EjectCommand.cs</DependentUpon> + <SubType>Designer</SubType> + </EmbeddedResource> <EmbeddedResource Include="Forms\MouseCommand.resx"> <DependentUpon>MouseCommand.cs</DependentUpon> <SubType>Designer</SubType> Modified: trunk/plugins/IR Server Suite/Common/IrssUtils/Win32.cs =================================================================== --- trunk/plugins/IR Server Suite/Common/IrssUtils/Win32.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/Common/IrssUtils/Win32.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -2,6 +2,7 @@ using System.Collections; using System.Runtime.InteropServices; using System.Security; +using System.Text; namespace IrssUtils { @@ -12,29 +13,16 @@ public static class Win32 { - #region Constants - - /// <summary> - /// Windows Message (USER). - /// </summary> - public const int WM_USER = 0x0400; - - /// <summary> - /// Windows Message (APP). - /// </summary> - public const int WM_APP = 0x8000; - - #endregion Constants - #region Enumerations - public enum WindowsMessages + public enum WindowsMessage { WM_ACTIVATE = 0x6, WM_ACTIVATEAPP = 0x1C, WM_AFXFIRST = 0x360, WM_AFXLAST = 0x37F, WM_APP = 0x8000, + WM_APPCOMMAND = 0x319, WM_ASKCBFORMATNAME = 0x30C, WM_CANCELJOURNAL = 0x4B, WM_CANCELMODE = 0x1F, @@ -240,29 +228,167 @@ WM_XBUTTONUP = 0x20C } + public enum SysCommand + { + SC_SIZE = 0xF000, + SC_MOVE = 0xF010, + SC_MINIMIZE = 0xF020, + SC_MAXIMIZE = 0xF030, + SC_NEXTWINDOW = 0xF040, + SC_PREVWINDOW = 0xF050, + SC_CLOSE = 0xF060, + SC_VSCROLL = 0xF070, + SC_HSCROLL = 0xF080, + SC_MOUSEMENU = 0xF090, + SC_KEYMENU = 0xF100, + SC_ARRANGE = 0xF110, + SC_RESTORE = 0xF120, + SC_TASKLIST = 0xF130, + SC_SCREENSAVE = 0xF140, + SC_HOTKEY = 0xF150, + SC_DEFAULT = 0xF160, + SC_MONITORPOWER = 0xF170, + SC_CONTEXTHELP = 0xF180, + SC_SEPARATOR = 0xF00F, + + SCF_ISSECURE = 0x00000001, + + SC_ICON = SC_MINIMIZE, + SC_ZOOM = SC_MAXIMIZE, + } + + public enum AppCommand + { + APPCOMMAND_BROWSER_BACKWARD = 1, + APPCOMMAND_BROWSER_FORWARD = 2, + APPCOMMAND_BROWSER_REFRESH = 3, + APPCOMMAND_BROWSER_STOP = 4, + APPCOMMAND_BROWSER_SEARCH = 5, + APPCOMMAND_BROWSER_FAVORITES = 6, + APPCOMMAND_BROWSER_HOME = 7, + APPCOMMAND_VOLUME_MUTE = 8, + APPCOMMAND_VOLUME_DOWN = 9, + APPCOMMAND_VOLUME_UP = 10, + APPCOMMAND_MEDIA_NEXTTRACK = 11, + APPCOMMAND_MEDIA_PREVIOUSTRACK = 12, + APPCOMMAND_MEDIA_STOP = 13, + APPCOMMAND_MEDIA_PLAY_PAUSE = 4143, + APPCOMMAND_MEDIA_PLAY = 4142, + APPCOMMAND_MEDIA_PAUSE = 4143, + APPCOMMAND_MEDIA_RECORD = 4144, + APPCOMMAND_MEDIA_FASTFORWARD = 4145, + APPCOMMAND_MEDIA_REWIND = 4146, + APPCOMMAND_MEDIA_CHANNEL_UP = 4147, + APPCOMMAND_MEDIA_CHANNEL_DOWN = 4148, + } + + [Flags] + public enum SendMessageTimeoutFlags + { + SMTO_NORMAL = 0x0000, + SMTO_BLOCK = 0x0001, + SMTO_ABORTIFHUNG = 0x0002, + SMTO_NOTIMEOUTIFNOTHUNG = 0x0008, + } + + [Flags] + public enum ShutdownReason + { + MajorApplication = 0x00040000, + MajorHardware = 0x00010000, + MajorLegacyApi = 0x00070000, + MajorOperatingSystem = 0x00020000, + MajorOther = 0x00000000, + MajorPower = 0x00060000, + MajorSoftware = 0x00030000, + MajorSystem = 0x00050000, + + MinorBlueScreen = 0x0000000F, + MinorCordUnplugged = 0x0000000b, + MinorDisk = 0x00000007, + MinorEnvironment = 0x0000000c, + MinorHardwareDriver = 0x0000000d, + MinorHotfix = 0x00000011, + MinorHung = 0x00000005, + MinorInstallation = 0x00000002, + MinorMaintenance = 0x00000001, + MinorMMC = 0x00000019, + MinorNetworkConnectivity = 0x00000014, + MinorNetworkCard = 0x00000009, + MinorOther = 0x00000000, + MinorOtherDriver = 0x0000000e, + MinorPowerSupply = 0x0000000a, + MinorProcessor = 0x00000008, + MinorReconfig = 0x00000004, + MinorSecurity = 0x00000013, + MinorSecurityFix = 0x00000012, + MinorSecurityFixUninstall = 0x00000018, + MinorServicePack = 0x00000010, + MinorServicePackUninstall = 0x00000016, + MinorTermSrv = 0x00000020, + MinorUnstable = 0x00000006, + MinorUpgrade = 0x00000003, + MinorWMI = 0x00000015, + + FlagUserDefined = 0x40000000, + //FlagPlanned = 0x80000000, + } + + [Flags] + public enum ExitWindows + { + // ONE of the following five: + LogOff = 0x00, + ShutDown = 0x01, + Reboot = 0x02, + PowerOff = 0x08, + RestartApps = 0x40, + // Optionally include ONE of the following two: + Force = 0x04, + ForceIfHung = 0x10, + } + #endregion Enumerations + #region Structures + + [StructLayout(LayoutKind.Sequential)] + public struct COPYDATASTRUCT + { + public int dwData; + public int cbData; + public int lpData; + } + + #endregion Structures + + #region Delegates + + public delegate bool EnumWindowsProc(IntPtr hWnd, int lParam); + + #endregion Delegates + #region Interop [DllImport("user32.dll")] + public static extern int EnumWindows(EnumWindowsProc ewp, int lParam); + + [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] public static extern bool SetForegroundWindow(IntPtr hWnd); - [Flags] - public enum SendMessageTimeoutFlags : int - { - SMTO_NORMAL = 0x0000, - SMTO_BLOCK = 0x0001, - SMTO_ABORTIFHUNG = 0x0002, - SMTO_NOTIMEOUTIFNOTHUNG = 0x0008, - } + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + static extern int GetWindowTextLength(IntPtr hWnd); + [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] + static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount); + [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern IntPtr SendMessageTimeout( - IntPtr windowHandle, + IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam, @@ -273,10 +399,14 @@ //[DllImport("user32.dll", SetLastError = false)] //public static extern IntPtr SendMessage(IntPtr windowHandle, int msg, IntPtr wordParam, IntPtr longParam); - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - public static extern int RegisterWindowMessage(string lpString); + //[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] + //public static extern int RegisterWindowMessage(string lpString); [DllImport("user32.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool ExitWindowsEx(ExitWindows uFlags, ShutdownReason dwReason); + + [DllImport("user32.dll", SetLastError = true)] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", SetLastError = true)] @@ -314,6 +444,17 @@ #region Methods + public static string GetWindowTitle(IntPtr hWnd) + { + int length = GetWindowTextLength(hWnd); + + StringBuilder windowTitle = new StringBuilder(length + 1); + + GetWindowText(hWnd, windowTitle, windowTitle.Capacity); + + return windowTitle.ToString(); + } + /// <summary> /// Given a 32-bit integer this method returns the High Word (upper 16 bits). /// </summary> @@ -387,6 +528,46 @@ } } + /// <summary> + /// Get an IntPtr pointing to any object. + /// </summary> + /// <param name="o">Object to get pointer for.</param> + /// <returns>Pointer to object.</returns> + public static IntPtr VarPtr(object o) + { + GCHandle handle = GCHandle.Alloc(o, GCHandleType.Pinned); + IntPtr ptr = handle.AddrOfPinnedObject(); + handle.Free(); + return ptr; + } + + /* + public static void ActivateWindowByHandle(IntPtr hWnd) + { + WindowPlacement windowPlacement; + GetWindowPlacement(hWnd, out windowPlacement); + + switch (windowPlacement.showCmd) + { + case SW_HIDE: //Window is hidden + ShowWindow(hWnd, SW_RESTORE); + break; + case SW_SHOWMINIMIZED: //Window is minimized + // if the window is minimized, then we need to restore it to its + // previous size. we also take into account whether it was + // previously maximized. + int showCmd = (windowPlacement.flags == WPF_RESTORETOMAXIMIZED) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL; + ShowWindow(hWnd, showCmd); + break; + default: + // if it's not minimized, then we just call SetForegroundWindow to + // bring it to the front. + SetForegroundWindow(hWnd); + break; + } + } + */ + #endregion Methods } Modified: trunk/plugins/IR Server Suite/IR Server Plugins/MCE Replacement Transceiver/MceIrApi.cs =================================================================== --- trunk/plugins/IR Server Suite/IR Server Plugins/MCE Replacement Transceiver/MceIrApi.cs 2007-08-03 11:33:59 UTC (rev 787) +++ trunk/plugins/IR Server Suite/IR Server Plugins/MCE Replacement Transceiver/MceIrApi.cs 2007-08-03 16:49:07 UTC (rev 788) @@ -16,74 +16,72 @@ #region Constants - public const int ID_MCEIR_KEYCODE = 0x37FF0; + const int ID_MCEIR_KEYCODE = 0x37FF0; #endregion #region Enumerations /// <summary> - /// The blaster port to send IR codes to + /// The blaster port to send IR codes to. /// </summary> public enum BlasterPort { /// <summary> - /// Send IR codes to both blaster ports + /// Send IR codes to both blaster ports. /// </summary> Both = 0, /// <summary> - /// Send IR codes to blaster port 1 only + /// Send IR codes to blaster port 1 only. /// </summary> Port_1 = 1, /// <summary> - /// Send IR codes to blaster port 2 only + /// Send IR codes to blaster port 2 only. /// </summary> Port_2 = 2 } /// <summary> - /// Type of blaster in use + /// Type of blaster in use. /// </summary> public enum BlasterType { /// <summary> - /// Device is a first party Microsoft MCE transceiver + /// Device is a first party Microsoft MCE transceiver. /// </summary> Microsoft = 0, /// <summary> - /// Device is an third party SMK MCE transceiver + /// Device is an third party SMK MCE transceiver. /// </summary> SMK = 1 } /// <summary> - /// Speed to transmit IR codes at + /// Speed to transmit IR codes at. /// </summary> public enum BlasterSpeed { /// <summa... [truncated message content] |