------ #### SuperDesign V3.0.2412.2001 - *.[新增]新增程序更新日志设置和自动发布功能。 - *.[修复]修复Post数据格式不正确时双击文本框会导致软件闪退的BUG。
114 lines
4.0 KiB
C#
114 lines
4.0 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 流程软件通信类
|
|
/// </summary>
|
|
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, int wParam, ref COPYDATASTRUCT IParam);
|
|
/// <summary>
|
|
/// 向指定句柄发送消息
|
|
/// </summary>
|
|
/// <param name="handle"></param>
|
|
/// <param name="wParam"></param>
|
|
/// <param name="str">要发送的文字内容</param>
|
|
public static void SendMsg(IntPtr handle, int 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);
|
|
}
|
|
/// <summary>
|
|
/// 发送消息到文本编辑器
|
|
/// </summary>
|
|
/// <param name="wParam">附带信息</param>
|
|
/// <param name="str">要发送的文字内容</param>
|
|
public static void SendMsgToEditor(string str)
|
|
{
|
|
object mainHandle = QuickMsg.RyMemoryShare.ReadFromMemory(1024, typeof(Int64), "SmartEditor");
|
|
if (mainHandle != null)
|
|
{
|
|
SendMsg((IntPtr)mainHandle.ToInt64(), 0, str);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 发送消息到指定的内存ID窗口
|
|
/// </summary>
|
|
/// <param name="MemoryId">内存ID</param>
|
|
/// <param name="wParam">附带信息标识</param>
|
|
/// <param name="str">发送的内容</param>
|
|
public static void SendMsg(string MemoryId, int 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);
|
|
}
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取消息字符串内容
|
|
/// </summary>
|
|
/// <param name="m"></param>
|
|
/// <returns></returns>
|
|
public static string GetMsg(Message m)
|
|
{
|
|
COPYDATASTRUCT cdata = new COPYDATASTRUCT();
|
|
Type mytype = cdata.GetType();
|
|
cdata = (COPYDATASTRUCT)m.GetLParam(mytype);
|
|
return cdata.lpData;
|
|
}
|
|
/// <summary>
|
|
/// 通知已打开的编辑器,显示界面
|
|
/// </summary>
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
}
|