Groups: Translators, Members, Administrators
Location: Tampa, FL
Thanks: 28 times
Was thanked: 404 time(s) in 349 post(s)
Starting with version 0.3.1.3, StrokesPlus.net accepts receiving a WM_COPYDATA
message to execute scripts via another program.
(Note: In version 0.3.1.4, the WParam parameter can be sent as 0 (zero, default) to signal the script string is Unicode, send 1 (one) to signal the script string is ANSI.)
This is a very specific use case that 99% of people will never need, but it was fairly easy to add, so why not!
If StrokesPlus.net is running elevated (installer version or portable running as Administrator), a non-elevated process cannot
send messages to a higher privilege process.
Also, the script executes with no context, just like a hotkey. Meaning there's no action
object available in the script, since it's not being started from an action.
These scripts will be run even is StrokesPlus.net is not active (disabled); as long as S+.net is running (and a script engine is available), it will execute the script.
Here's is example C# code that has all of the code necessary to send the message:
public void SendScript(string script)
IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, "StrokesPlus.net Gesture Surface");
byte sarr = System.Text.Encoding.Unicode.GetBytes(script);
int len = sarr.Length;
cds.dwData = (IntPtr)100; //100 (hex 0x64) instructs S+ that you're sending a script
cds.lpData = script; //String is assumed to be Unicode, not ANSI
cds.cbData = len + 1;
SendMessage(hWnd, WM_COPYDATA, IntPtr.Zero, ref cds);
public const int WM_COPYDATA = 0x4A;
public struct COPYDATASTRUCT
public IntPtr dwData;
public int cbData;
public string lpData;
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = false)]
internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);
Then you can just call:
SendScript("sp.MessageBox('Hi from WM_COPYDATA!', 'WM_COPYDATA');");
Edited by user Tuesday, June 18, 2019 12:06:20 AM(UTC)
| Reason: Not specified
2 users thanked Rob for this useful post.