Commanding Rainmeter with AHK (and vice versa)

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: Commanding Rainmeter with AHK (and vice versa)

Post by joedf » 31 Jul 2021, 16:45

Glad I could help! :+1:
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
Yincognito
Posts: 1
Joined: 23 Nov 2023, 14:29

Re: Commanding Rainmeter with AHK (and vice versa)

Post by Yincognito » 23 Nov 2023, 15:19

I know it's a v1 section of the forum, but can someone convert the 2nd code from the initial post here to one that can be compiled with v2 (32bit mostly, though 64bit wouldn't hurt):

Code: Select all

SendRainmeterCommand(command) {
  Send_WM_COPYDATA(command, "DummyRainWClass")
}

Send_WM_COPYDATA(ByRef StringToSend, ByRef TargetWindowClass)  ; ByRef saves a little memory in this case.
; This function sends the specified string to the specified window and returns the reply.
; Cribbed from https://www.autohotkey.com/docs/commands/OnMessage.htm
{
    VarSetCapacity(CopyDataStruct, 3*A_PtrSize, 0)  ; Set up the structure's memory area.
    ; First set the structure's cbData member to the size of the string, including its zero terminator:
    SizeInBytes := (StrLen(StringToSend) + 1) * (A_IsUnicode ? 2 : 1)
    NumPut(1, CopyDataStruct) ; Per example at https://docs.rainmeter.net/developers/
    NumPut(SizeInBytes, CopyDataStruct, A_PtrSize)  ; OS requires that this be done.
    NumPut(&StringToSend, CopyDataStruct, 2*A_PtrSize)  ; Set lpData to point to the string itself.
    SendMessage, 0x4a, 0, &CopyDataStruct,, ahk_class %TargetWindowClass%  ; 0x4a is WM_COPYDATA. Must use Send not Post.
    return ErrorLevel  ; Return SendMessage's reply back to our caller.
}
I tried to do it myself, but even after adapting some obvious parts like NumPut(), A_IsUnicode or SendMessage to v2, I'm still getting various errors and warnings... :think:
Post Reply

Return to “Scripts and Functions (v1)”