@Ragnar
Receiver.ahk (run first):
Code: Select all
#Requires AutoHotkey v2.0
; Register a new window message with the custom name "NewAHKScript"
MsgNum := DllCall("RegisterWindowMessage", "Str", "NewAHKScript")
OnMessage(MsgNum, NewScriptCreated)
Persistent()
NewScriptCreated(wParam, lParam, msg, hwnd) {
Loop {
ib := InputBox("Script with hWnd " hwnd " sent message:`n`nwParam: " wParam "`nlParam: " lParam "`n`nReply:", "Message")
if ib.Result = "Cancel"
return 0
else if !IsInteger(IB.Value)
MsgBox "The reply can only be a number", "Error"
else
return IB.Value
}
}
Sender, waits indefinitely:
Code: Select all
#Requires AutoHotkey v2.0
DetectHiddenWindows 1
receiverhWnd := WinExist("Receiver.ahk ahk_class AutoHotkey")
MsgNum := DllCall("RegisterWindowMessage", "Str", "NewAHKScript")
reply := SendMessage(MsgNum, 123, -456,, receiverhWnd,,,, 0)
MsgBox "Got reply: " reply
Sender, times out immediately:
Code: Select all
#Requires AutoHotkey v2.0
DetectHiddenWindows 1
receiverhWnd := WinExist("Receiver.ahk ahk_class AutoHotkey")
MsgNum := DllCall("RegisterWindowMessage", "Str", "NewAHKScript")
reply := SendMessage(MsgNum, 123, -456,, receiverhWnd,,,, 0xFFFFFFFF)
MsgBox "Got reply: " reply
Sender, SendMessage with default timeout (times out in 5 seconds):
Code: Select all
#Requires AutoHotkey v2.0
DetectHiddenWindows 1
receiverhWnd := WinExist("Receiver.ahk ahk_class AutoHotkey")
MsgNum := DllCall("RegisterWindowMessage", "Str", "NewAHKScript")
reply := SendMessage(MsgNum, 123, -456,, receiverhWnd)
MsgBox "Got reply: " reply