It is currently May 19th, 2024, 5:38 pm

Receiving Window Messages

Get help with creating, editing & fixing problems with skins
User avatar
Jax
Posts: 104
Joined: June 7th, 2021, 11:46 am

Receiving Window Messages

Post by Jax »

Hello there. From what I understand, The WindowMessage plugin only sends window messages, and listens to the reply. Is there a way to make the skin window receive specific window messages with an id? Or is there a plugin for this task?
User avatar
Jax
Posts: 104
Joined: June 7th, 2021, 11:46 am

Re: Receiving Window Messages

Post by Jax »

Does anyone have any ideas about this? :(
User avatar
Brian
Developer
Posts: 2695
Joined: November 24th, 2011, 1:42 am
Location: Utah

Re: Receiving Window Messages

Post by Brian »

Jax wrote: June 13th, 2022, 10:32 am Is there a way to make the skin window receive specific window messages with an id? Or is there a plugin for this task?
Not with this plugin, but then again, a Windows message might not be the best way to send information to a Rainmeter skin.

It might help if you could describe what you are trying to do, because it sounds as if you are trying to send a specific skin some information from another application (or script). If that is the case, it would probably be best to just send a bang to the main Rainmeter application (utilizing the config parameter of the bang to make sure it gets to the right skin).

https://docs.rainmeter.net/manual/bangs/
Example: "C:\Program Files\Rainmeter\Rainmeter.exe" !SetOption SomeStringMeter Text "SomeValue" "MySuite\MySkin"


Another option is using the Rainmeter API from an external application, but this is mainly for getting Rainmeter path information, or a skins window handle. We have some information here to get you started, but obviously implementing this from whatever external application you are using is going be difficult to provide support for, at least on our end.
https://docs.rainmeter.net/developers/#SendMessage

Some of the query id's are located here: https://github.com/rainmeter/rainmeter/blob/master/Library/RainmeterQuery.h

-Brian
User avatar
Jax
Posts: 104
Joined: June 7th, 2021, 11:46 am

Re: Receiving Window Messages

Post by Jax »

Brian wrote: June 18th, 2022, 6:01 am It might help if you could describe what you are trying to do, because it sounds as if you are trying to send a specific skin some information from another application (or script). If that is the case, it would probably be best to just send a bang to the main Rainmeter application (utilizing the config parameter of the bang to make sure it gets to the right skin).
I am trying to send a window message to rainmeter from an ahk script for this project. Currently, it works by the method you mentioned (sending a bang to the application), but it causes a loading icon to appear next to the most cursor (since it is starting a new instance of the program). I am able to send window messages to the skin window with ahk with ease, but there are no ways to interpret them in Rainmeter.
User avatar
Smurth
Posts: 12
Joined: February 2nd, 2019, 2:10 pm

Re: Receiving Window Messages

Post by Smurth »

It might be too late, but...

Code: Select all

	Bang(str) {
		d := Buffer(24, 0)
		l := (StrLen(str) + 1) * 2
		NumPut("UPtr", 1, d)
		NumPut("UPtr", l, d, 8)
		NumPut("UPtr", StrPtr(str), d, 16)
		dhw := A_DetectHiddenWindows
		DetectHiddenWindows 1
		SendMessage(0x4a, 0, d.Ptr,, WinExist("ahk_class DummyRainWClass"))
		DetectHiddenWindows dhw
	}
User avatar
Yincognito
Rainmeter Sage
Posts: 7287
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Receiving Window Messages

Post by Yincognito »

Smurth wrote: May 4th, 2024, 4:24 pm It might be too late, but...

Code: Select all

	Bang(str) {
		d := Buffer(24, 0)
		l := (StrLen(str) + 1) * 2
		NumPut("UPtr", 1, d)
		NumPut("UPtr", l, d, 8)
		NumPut("UPtr", StrPtr(str), d, 16)
		dhw := A_DetectHiddenWindows
		DetectHiddenWindows 1
		SendMessage(0x4a, 0, d.Ptr,, WinExist("ahk_class DummyRainWClass"))
		DetectHiddenWindows dhw
	}
Is this tested? And if so, is it for AHK v.1, or for AHK v.2 (as the NumPut() syntax imples)? If the latter, then it's definitely not too late, at least for me. I've been successfully using this for AHK v.1:

Code: Select all

SendBang(ByRef Bang)
{
  cWnd := "RainmeterMeterWindow"
  iLen := (StrLen(Bang) + 1) * (A_IsUnicode ? 2 : 1)
  VarSetCapacity(pCds, 3 * A_PtrSize, 0)
  NumPut(1, pCds)
  NumPut(iLen, pCds, A_PtrSize)
  NumPut(&Bang, pCds, 2 * A_PtrSize)
  SendMessage, 0x004A, 0, &pCds,, ahk_class %cWnd%
  return ErrorLevel
}
but I was having trouble "converting" it to a v.2 version, so if what you posted is a correct v.2 implementation, that should help me in having both AutoIt 3, AutoHotkey 1 and AutoHotKey 2 versions of a "window spy" script for a WindowMessage plugin skin (only the AHK v.2 version is missing at the moment). :D

One other thing, I suppose your:

Code: Select all

		dhw := A_DetectHiddenWindows
		DetectHiddenWindows 1
		DetectHiddenWindows dhw
is an equivalent to DetectHiddenWindows, On at the start of the script, right?
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Smurth
Posts: 12
Joined: February 2nd, 2019, 2:10 pm

Re: Receiving Window Messages

Post by Smurth »

Yes, it's for v2 (that's the "official" release now).
And yes,

Code: Select all

DetectHiddenWindows 1
is equivalent to

Code: Select all

DetectHiddenWindows, On
.
User avatar
Yincognito
Rainmeter Sage
Posts: 7287
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Receiving Window Messages

Post by Yincognito »

Smurth wrote: May 7th, 2024, 5:44 am Yes, it's for v2 (that's the "official" release now).
And yes,

Code: Select all

DetectHiddenWindows 1
is equivalent to

Code: Select all

DetectHiddenWindows, On
.
Thanks, I'll test it later on. Hopefully, it will work (which it does). :thumbup: :rosegift:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth
User avatar
Smurth
Posts: 12
Joined: February 2nd, 2019, 2:10 pm

Re: Receiving Window Messages

Post by Smurth »

@Yincognito:
Out of subject but you might find this usefull: sending strings from Rainmeter to AHK

default.ini :

Code: Select all

[Message]
Measure=Plugin
Plugin=WindowMessagePlugin
WindowClass=AutoHotkey
;WindowName=

[lua]
UpdateDivider=-1
Measure=Script
ScriptFile=default.lua

[MyMeter]
Meter=Image
LeftMouseUpAction=[!CommandMeasure lua "Send('#CURRENTSECTION#')"]

default.lua :

Code: Select all

function Send(str)
	for c in string.gmatch(str, ".") do
		SKIN:Bang('!CommandMeasure', 'Message', 'SendMessage 8192 0 ' .. string.byte(c))
	end
	SKIN:Bang('!CommandMeasure', 'Message', 'SendMessage 8192 1 0')
end
myScript.ahk (v2) :

Code: Select all

		OnMessage 0x2000, Msg

		Msg(wParam, lParam, msg, hwnd, *) {
			Static str := ""
			if wParam {
				ProcessTheReceivedString(str)
				str := ""
			} else
				str .= Chr(lParam)
		}
		
		ProcessTheReceivedString(str) {
			MsgBox str
		}
User avatar
Yincognito
Rainmeter Sage
Posts: 7287
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Receiving Window Messages

Post by Yincognito »

Smurth wrote: May 9th, 2024, 7:35 am @Yincognito:
Out of subject but you might find this usefull: sending strings from Rainmeter to AHK
Actually, this is precisely on (my own) subject, since I do indeed have a string communication system between the skin and AutoHotKey / AutoIt, based on passing script parameters (like the returned bang structure, for example) in a RunCommand measure from the former, and sending bangs (with the script result) from the latter. As you probably realize though, passing script parameters is only suited for sending the string at the moment when the script is run, while your excellent solution should also work at any moment during the script's execution, which is great and something I've been wondering about too!

Thanks again for these nice solutions - I'll test them later on, but for sure they will be very useful if I want to change the value of some script parameter after I already spawned the script executable from the skin. :thumbup:
Profiles: Rainmeter ProfileDeviantArt ProfileSuites: MYiniMeterSkins: Earth