using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using System.Diagnostics; using System.Windows.Forms; using ryCommon; using QuickMsg; using System.Runtime.CompilerServices; using System.Threading; namespace ryConfig { /// /// 流程软件通信类 /// public class MsgManager { [DllImport("user32.dll", EntryPoint = "GetParent", SetLastError = true)] private static extern IntPtr GetParent(IntPtr hWnd); [DllImport("user32.dll", EntryPoint = "GetWindowThreadProcessId")] private static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId); [DllImport("user32.dll", EntryPoint = "IsWindow")] private static extern bool IsWindow(IntPtr hWnd); private const int WM_COPYDATA = 0x004A; public struct COPYDATASTRUCT { public IntPtr dwData; public int cData; [MarshalAs(UnmanagedType.LPStr)] public string lpData; } [DllImport("User32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage(IntPtr hwnd, int msg, long wParam, ref COPYDATASTRUCT IParam); /// /// 向指定句柄发送消息 /// /// /// /// 要发送的文字内容 public static void SendMsg(IntPtr handle, long wParam, string str) { byte[] arr = System.Text.Encoding.Default.GetBytes(str); int len = arr.Length; COPYDATASTRUCT cdata; cdata.dwData = (IntPtr)100; cdata.lpData = str; cdata.cData = len + 1; SendMessage(handle, WM_COPYDATA, wParam, ref cdata); } /// /// 发送消息到文本编辑器 /// /// 附带信息 /// 要发送的文字内容 public static void SendMsgToEditor(string str) { object mainHandle = QuickMsg.RyMemoryShare.ReadFromMemory(1024, typeof(Int64), "SmartEditor"); if (mainHandle != null) { SendMsg((IntPtr)mainHandle.ToInt64(), 0, str); } } /// /// 发送消息到指定的内存ID窗口 /// /// 内存ID /// 附带信息标识 /// 发送的内容 public static void SendMsg(string MemoryId, long wParam, string str) { if (MemoryId == null || MemoryId.Length == 0) { return; } else { object mainHandle = QuickMsg.RyMemoryShare.ReadFromMemory(1024, typeof(Int64), MemoryId); if (mainHandle != null && (long)mainHandle != 0) { SendMsg((IntPtr)mainHandle.ToInt64(), wParam, str); } } } /// /// 获取消息字符串内容 /// /// /// public static string GetMsg(Message m) { COPYDATASTRUCT cdata = new COPYDATASTRUCT(); Type mytype = cdata.GetType(); cdata = (COPYDATASTRUCT)m.GetLParam(mytype); return cdata.lpData; } /// /// 通知已打开的编辑器,显示界面 /// public static void ShowEditorUI() { object mainHandle = QuickMsg.RyMemoryShare.ReadFromMemory(1024, typeof(Int64), "SmartEditor"); if (mainHandle != null && (long)mainHandle != 0) { ryControls.Win32.SendMessage(new IntPtr((long)mainHandle), 17189, 100, 100);//让界面显示 return; } } } }