static void MessageManagerMessageReceived(object sender, MessageReceivedEventArgs e) { string[] tokens = e.Message.Split(' '); bool hasParans = tokens.Length > 1; CommandMap.Commands command = CommandMap.FindCommand(tokens[0]); switch (command) { case CommandMap.Commands.Help: case CommandMap.Commands.Loadfile: e.Response = CommunicationBridge.ResponseError + " Not implemented yet"; break; case CommandMap.Commands.Quit: e.Response = CommunicationBridge.ResponseError + " Command invalid on this context."; break; case CommandMap.Commands.UnloadApplication: e.Response = CommunicationBridge.UnloadApplication(); break; case CommandMap.Commands.Sendkeys: if (hasParans) { e.Response = CommunicationBridge.SendKeys(string.Join(" ", tokens.Skip(1).ToArray())); } break; case CommandMap.Commands.SendMacro: if (hasParans) { e.Response = CommunicationBridge.SendMacro(string.Join(" ", tokens.Skip(1).ToArray())); } break; case CommandMap.Commands.ListKeys: e.Response = CommunicationBridge.ListKeys(); return; case CommandMap.Commands.SendToTray: e.Response = CommunicationBridge.SendMainWindowToTray(); return; case CommandMap.Commands.RestoreWindow: e.Response = CommunicationBridge.RestoreMainWindowsFromTray(); return; case CommandMap.Commands.StartSocketServer: e.Response = CommunicationBridge.StartSocketServer(); return; case CommandMap.Commands.StopSocketServer: e.Response = CommunicationBridge.StopSocketServer(); return; default: e.Response = CommunicationBridge.ResponseError + " Unknow command: " + tokens[0]; break; } }
protected override void WndProc(ref Message m) { switch (m.Msg) { case Win32SupportCode.WM_COPYDATA: Win32SupportCode.CopyDataStruct st = (Win32SupportCode.CopyDataStruct)Marshal.PtrToStructure(m.LParam, typeof(Win32SupportCode.CopyDataStruct)); string strData = Marshal.PtrToStringUni(st.lpData); _messageReceived = strData; if (!string.IsNullOrEmpty(_messageReceived)) { int i = _messageReceived.IndexOf("#"); bool requestResponse = _messageReceived.Substring(i + 1, 1) == "0" ? false : true; string sourceMessageManager = _messageReceived.Substring(0, i); string message = _messageReceived.Substring(i + 2); if (_waitingResponse) { _timeOut.Stop(); _responseReceived = message; _waitingResponse = false; } else { var messageReceivedEventArgs = new MessageReceivedEventArgs(sourceMessageManager, message); if (MessageReceived != null) MessageReceived(this, messageReceivedEventArgs); if (requestResponse) { if (m.WParam == IntPtr.Zero) { SendMessage(sourceMessageManager, messageReceivedEventArgs.Response); } else { SendMessage(m.WParam, messageReceivedEventArgs.Response); } } } } break; default: // let the base class deal with it base.WndProc(ref m); break; } }