Send and receive messages

For receiving, using Embedded functions in AutoHotkey only the first command works.
Besides passing the command to dopusrt.exe multiple times, is there any way to pass it all in one go?

    DOpusrt := "C:\Program Files\GPSoftware\Directory Opus\dopusrt.exe"
    run DOpusrt ' /acmd ' '
(
Go "D:\" NEWTAB
[Set VIEW=thumbnails]
)'

For sending I tried using DDE Functions, doesn't work for AutoHotkey. The remaining way seems to be to use cache file.

2 Likes

FWIW, I used to create a UserCommand that executes the desired commands, structured in a way that it can receive all the necessary args from Autohotkey. Depending on the commands you plan to execute, but the args are usually reused

I prefer the built-in method of DOpus, which can be used directly by other users and machines.

Only way to run multiple commands via a single DOpusRT.exe command line is to run them via a user-command or script-command.

OK, I hope that SendMessage and OnMessage like AutoHotkey can be added in the future.

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")
}

DOpus seems to support sending and receiving messages. Can you list more parameters sent to DOpus? listsel

Or please make the first parameter of DOpus.SendCustomMsg() support window handle, then I can customize everything.

	hwnd = 26286408;
	msg = "Test";
	DOpus.SendCustomMsg(hwnd, msg)

0x4A Receive message

#Requires AutoHotkey 2
#SingleInstance Force
Persistent

msgbox "Script hwnd: " A_ScriptHwnd

OnMessage(0x4A, Receive_WM_COPYDATA)  ; 0x004A is WM_COPYDATA

/*
Receive_WM_COPYDATA(wParam, lParam, *) {
    COPYDATA := lParam
    dataReceived := NumGet(COPYDATA + A_PtrSize * 2, "Ptr")

    dataSize := NumGet(COPYDATA + A_PtrSize, "UInt")

    dataReceived := StrGet(dataReceived, dataSize, "UTF-8")
	msgbox "Data Received:`n" dataReceived
}
*/

Receive_WM_COPYDATA(wParam, lParam, *) {
	dataReceived := StrGet(
		NumGet(lParam + 2 * A_PtrSize, 'Ptr'),   ; COPYDATASTRUCT.lpData, ptr to a str presumably
		NumGet(lParam + A_PtrSize, 'UInt') / 2   ; COPYDATASTRUCT.cbData, count bytes of lpData, /2 to get count chars in unicode str
	)
	msgbox "Data Received:`n" dataReceived
}