StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ss92671  
#1 Posted : Friday, August 16, 2024 11:25:48 AM(UTC)
ss92671

Rank: Newbie

Reputation:

Groups: Approved
Joined: 2/12/2023(UTC)
Posts: 1
China

Was thanked: 1 time(s) in 1 post(s)
首先,为SystemWindow类增加了CopyData方法,向指定窗口发送WM_COPYDATA命令时代码更加简洁。其次,能够接收WM_COPYDATA命令,方便与其他程序交互。
First, the CopyData method was added to the SystemWindow class, making the code more concise when sending the WM_COPYDATA command to a specified window. Second, it can now receive the WM_COPYDATA command, facilitating interaction with other programs.

参考代码,Reference code
Code:
action.Window.CopyData(4194305, `::copydata ${new CopyDataProgram().HWnd.ToInt32()}, "sp.StoreString('xyCurrentPath','<curpath>');\0";`);
// sp.WindowFromClassOrTitle("ThunderRT6FormDC", "").CopyData(4194305, `::copydata ${new CopyDataProgram().HWnd.ToInt32()}, "sp.StoreString('xyCurrentPath','<curpath>');sp.StoreString('xySelectedFiles','<selitems |>');\0";`);
sp.Sleep(30);
const xyCurrentPath = sp.GetStoredString("xyCurrentPath");

上述代码直接获取XYplorer的当前路径,其中"new CopyDataProgram().HWnd"为插件接收WM_COPYDATA命令时的句柄
The above code directly retrieves the current path of XYplorer. The "new CopyDataProgram().HWnd" is the handle for receiving the WM_COPYDATA command in the plugin.


Code:
action.Window.CopyData(0x44646557, "[CmdDuplicateInNewWindow]\0");

向当前SumatraPDF窗口发送CmdDuplicateInNewWindow命令
Send the "CmdDuplicateInNewWindow" command to the current SumatraPDF window.

Code:
action.Window.CopyData(0x44646557, "[CmdCopyFilePath]\0");
sp.Sleep(10);
const filePath = clip.GetText();

获取当前SumatraPDF窗口的文件路径
Get the file path of the current SumatraPDF window.

Code:
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using StrokesPlus.net;
using StrokesPlus.net.Code;

namespace CopyDataExtensions
{
	public static class SystemWindowExtensions
	{
		private const uint WM_COPYDATA = 0x4A;

		[DllImport("user32.dll", CharSet = CharSet.Unicode)]
		internal static extern IntPtr SendMessage(HandleRef hWnd, uint Msg, IntPtr wParam, ref WinAPIFunctions.COPYDATASTRUCT lParam);
		public static IntPtr CopyData(this SystemWindow wnd, long dwData, string str)
		{
			int len = Encoding.Unicode.GetByteCount(str);
			var copydatastruct = new WinAPIFunctions.COPYDATASTRUCT
			{
				dwData = (IntPtr)dwData,
				cbData = len + 1,
				lpData = str
			};
			return SendMessage(new HandleRef(wnd, wnd.HWnd), WM_COPYDATA, IntPtr.Zero, ref copydatastruct);
		}
	}
	public class CopyDataProgram : Form
	{

		private const uint WM_COPYDATA = 0x4A;

		[DllImport("user32.dll", CharSet = CharSet.Unicode)]
		private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);

		[DllImport("user32.dll", CharSet = CharSet.Unicode)]
		internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref WinAPIFunctions.COPYDATASTRUCT lParam);

		public static IntPtr SendScript(string str)
		{
			int len = Encoding.Unicode.GetByteCount(str);
			var copydatastruct = new WinAPIFunctions.COPYDATASTRUCT
			{
				dwData = (IntPtr)100,
				cbData = len + 1,
				lpData = str
			};
			IntPtr programHWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, "StrokesPlus.net Gesture Surface");
			return SendMessage(programHWnd, WM_COPYDATA, IntPtr.Zero, ref copydatastruct);
		}
		public IntPtr HWnd
		{
			get
			{
				return this.Handle;
			}
		}
		protected override void WndProc(ref Message m)
		{
			if (m.Msg == WM_COPYDATA)
			{
				var copydatastruct = (WinAPIFunctions.COPYDATASTRUCT)m.GetLParam(typeof(WinAPIFunctions.COPYDATASTRUCT));

				int dwData = copydatastruct.dwData.ToInt32();
				string lpData = copydatastruct.lpData;

				if (dwData >= 4194304 && dwData <= 4194307)
				{
					lpData = lpData.Replace("\\", "\\\\"); // XYplorer path conversion
				}
				SendScript(lpData);
			}

			base.WndProc(ref m);
		}

	}
}


以上为插件代码,将上述代码另外为cs文件,例如C:\CopyData.cs,利用如下命令编译
To compile the above code as a separate cs file, for example C:\CopyData.cs, you can use the following command:
Code:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /target:library /out:C:\CopyData.dll /reference:"C:\Program Files\StrokesPlus\StrokesPlus.net.exe" C:\CopyData.cs

命令将代码C:\CopyData.cs编译为插件C:\CopyData.dll,csc.exe为.net编译器,/reference参数指定为StrokesPlus.net.exe的路径
The command compiles the code C:\CopyData.cs into the plugin C:\CopyData.dll. The csc.exe is the .NET compiler, and the /reference parameter specifies the path to StrokesPlus.net.exe.
thanks 1 user thanked ss92671 for this useful post.
More on 10/9/2024(UTC)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.