Now that we have some methods in our script, it would be nice if we could expand upon them.
Receive Message
// Receive Message
// (c) 2024 Ken
// This is a script for Directory Opus.
// See https://www.gpsoft.com.au/endpoints/redirect.php?page=scripts for development information.
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "Receive Message";
initData.version = "1.0";
initData.copyright = "(c) 2024 Ken";
// initData.url = "https://resource.dopus.com/c/buttons-scripts/16";
initData.desc = "";
initData.default_enable = true;
initData.min_version = "13.0";
}
function OnAddCommands(addCmdData)
{
var cmd = addCmdData.AddCommand();
cmd.name = "ReceiveMessage";
cmd.method = "OnReceiveMessage";
cmd.desc = "Receive Message";
cmd.label = "Receive Message";
cmd.template = "";
cmd.hide = false;
cmd.icon = 'script';
}
function OnReceiveMessage(scriptCmdData)
{
var dlg = scriptCmdData.func.Dlg();
if (!DOpus.version.AtLeast("13.7.1"))
{
dlg.request("Receive Message\rThis script requires version 13.7.1 and above!", "OK");
return
}
dlg.msgonly = true;
dlg.create();
dlg.AddCustomMsg("Receive Message");
var cmd = scriptCmdData.func.command, msg;
do
{
msg = dlg.GetMsg();
if (!msg.result)
break;
var value = msg.value;
var event = msg.event;
var ctrl = msg.control;
var data = msg.data;
var object = msg.object;
DOpus.Output("Event: " + event + ", Value: " + value + " ctrl: " + ctrl + " data:" + data);
if (data == 1111)
break
if (object)
DOpus.Output("object:" + object[1]);
}
while (msg); // msg loop
}
// Called when Directory Opus starts up
function OnStartup(startupData)
{
cmd = DOpus.Create.Command;
cmd.RunCommand('ReceiveMessage')
}
Send Message
function OnClick(clickData) {
msg = DOpus.Create.Map();
msg(1) = "Test";
DOpus.SendCustomMsg("Receive Message", msg)
//DOpus.SendCustomMsg("Receive Message", 1111) // Exit
}
This AutoHotkey code works for both software I use, just need to modify the value 5000 and the window title.
#Requires AutoHotkey v2
f3::
{
if winExist("ahk_class SeerWindowClass")
Send_WM_COPYDATA("D:\test.txt")
}
return
Send_WM_COPYDATA(message) {
size := StrLen(message)
COPYDATA := Buffer(A_PtrSize * 3)
NumPut("Ptr", 5000, COPYDATA, 0)
NumPut("UInt", size * 2, COPYDATA, A_PtrSize)
NumPut("Ptr", StrPtr(message), COPYDATA, A_PtrSize * 2)
return SendMessage(0x004A, 0, COPYDATA,, "ahk_class SeerWindowClass",,,, TimeOut:=5000) ; 0x004A is WM_COPYDATA.
;return DllCall("User32.dll\SendMessageW", "Ptr", winExist("ahk_class SeerWindowClass"), "UInt", 74, "Ptr", 0, "Ptr", COPYDATA, "Ptr")
;return DllCall("User32.dll\SendMessageTimeout", "Ptr", winExist("ahk_class SeerWindowClass"), "UInt", 74, "Ptr", 0, "Ptr", COPYDATA, "UInt", 2, "UInt", TimeOut:=5000, "PtrP", Result:=0, "Ptr")
}