### DyLine V2.0.2509.1101 - *.[改进]消息发送机制采用Unicode。 ### VSoft V2.0.2509.1101 - *.[新增]支持对启动软件设置是否开机启动。 - *.[改进]防止快速点击分类时激活拖放功能。 - *.[改进]主窗体软件版本号改为默认从VSoft.dll获取。 - *.[改进]针对调用流程软件的功能,直接通过主程序实现,提升打开速度。 - *.[修复]修复添加内置功能后不能直接打开,需要二次启动后才能打开的BUG。 - *.[修复]修复拖放文件到列表,图标可能无法正常显示的BUG。 - *.[修复]修复从桌面拖放到列表,图标无法马上显示的BUG。 - *.[修复]修改软件后缓存图标不会更新的BUG。
112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace DyLine
|
|
{
|
|
public class ClsMsg
|
|
{
|
|
[DllImport("user32.dll", EntryPoint = "EnumWindows", SetLastError = true)]
|
|
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, uint lParam);
|
|
|
|
[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;
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
public struct COPYDATASTRUCT
|
|
{
|
|
public IntPtr dwData;
|
|
public int cData;
|
|
[MarshalAs(UnmanagedType.LPWStr)]
|
|
public string lpData;
|
|
}
|
|
[DllImport("User32.dll", CharSet = CharSet.Unicode, EntryPoint = "SendMessage")]
|
|
private static extern int SendMessage(int hwnd, int msg, int wParam, ref COPYDATASTRUCT IParam);
|
|
private delegate bool WNDENUMPROC(IntPtr hwnd, uint lParam);
|
|
public void SendMsg(int handle, int wParam, string str)
|
|
{
|
|
byte[] arr = System.Text.Encoding.Unicode.GetBytes(str);
|
|
int len = arr.Length;
|
|
COPYDATASTRUCT cdata;
|
|
cdata.dwData = (IntPtr)100;
|
|
cdata.lpData = str;
|
|
cdata.cData = (len + 1)*2;
|
|
SendMessage(handle, WM_COPYDATA, wParam, ref cdata);
|
|
}
|
|
|
|
readonly string msgText = "";
|
|
readonly int _wParam = 0;
|
|
//public void SendMsgToryProcess(int wParam,string str)
|
|
//{
|
|
// IntPtr ptrWnd = IntPtr.Zero;
|
|
// Process[] items = Process.GetProcessesByName("ryProcessManager");
|
|
// msgText = str;
|
|
// _wParam = wParam;
|
|
// for (int i = 0; i < items.Length; i++)
|
|
// {
|
|
// uint uiPid = (uint)items[i].Id; // 进程 ID
|
|
// bool bResult = EnumWindows(new WNDENUMPROC(EnumWindowsProc), uiPid);
|
|
// }
|
|
//}
|
|
public void SendMsgToryProcess(int wParam, string str)
|
|
{
|
|
for (int i = 1; i < 5; i++)
|
|
{
|
|
object mainHandle = ryCommon.Model.ryMemoryShare.ReadFromMemory(1024, typeof(int), "ryProcessManager" + i.ToString());
|
|
if (mainHandle != null)
|
|
{
|
|
SendMsg((int)mainHandle, wParam, str);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
public void SendMsgToryProcess(int wParam, string MemoryId, string str)
|
|
{
|
|
if (MemoryId == null || MemoryId.Length == 0)
|
|
{
|
|
SendMsgToryProcess(wParam, str);
|
|
}
|
|
else
|
|
{
|
|
object mainHandle = ryCommon.Model.ryMemoryShare.ReadFromMemory(1024, typeof(int), MemoryId);
|
|
if (mainHandle != null)
|
|
{
|
|
SendMsg((int)mainHandle, wParam, str);
|
|
}
|
|
}
|
|
}
|
|
public static string GetMsg(Message m)
|
|
{
|
|
COPYDATASTRUCT cdata = new COPYDATASTRUCT();
|
|
Type mytype = cdata.GetType();
|
|
cdata = (COPYDATASTRUCT)m.GetLParam(mytype);
|
|
return cdata.lpData;
|
|
}
|
|
private bool EnumWindowsProc(IntPtr hwnd, uint lParam)
|
|
{
|
|
uint uiPid = 0;
|
|
|
|
if (GetParent(hwnd) == IntPtr.Zero)
|
|
{
|
|
GetWindowThreadProcessId(hwnd, ref uiPid);
|
|
if (uiPid == lParam) // 找到进程对应的主窗口句柄
|
|
{
|
|
SendMsg(hwnd.ToInt32(), _wParam, msgText);
|
|
//return false; // 返回 false 以终止枚举窗口
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|